ADO.NET :: Acquisition Of The Last Stored Record - Datareader?
Aug 3, 2010How do I get the last stored record with data reader?
View 3 RepliesHow do I get the last stored record with data reader?
View 3 RepliesI'm having a method that exports content from the database to excel files. The method taks as paramaters a DataReader param and a int param - the number of rows. For the number of rows i'm using a dataset, wich i fill using the same query as for the datareader. So I'm executing it twice... Is there a way I can avoid that? get the number of rows from the datareader?
View 1 RepliesI am getting an error that an open DataReader associated with this Command, when I'm not using datareader(though probably executereader() is the same thing) how would I close this if I don't have a datareader present?
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
SqlCommand cmd = new SqlCommand("spSelectAllTypes",conn);
cmd.CommandType = CommandType.StoredProcedure;
[code]...
I just want to be able to databind a bunch of dropdownlist in one open connection. (before I had multiple open and closes for each control)
i am getting this error while fetching select statement in oracle pl/sql proc... ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'SP_CLASS' ORA-06550: line 1, column 7: PL/SQL: Statement ignored My proc is like..PROCEDURE "SP_CLASS" ( iDec IN NUMBER := null, p_ICID in number := null, p_DATA OUT SYS_REFCURSOR) IS BEGIN if(iDec = 1) then open p_DATA for SELECT ICID AS ID, SNAME AS NAME FROM SETUP_CLASS; else if(iDec = 2) then open p_DATA for SELECT ICID AS ID, SNAME AS NAME FROM SETUP_CLASS where ICID = p_ICID ; end if; end if; END;
View 1 RepliesSuppose you have the following... An ASP.NET web application that calls a stored procedure to delete a record. The table has a trigger on it that will insert an audit entry each time a record is deleted. I want to be able to record in the audit entry the username of who deleted the record. What would be the best way to go about achieving this? I know I could remove the trigger and have the delete stored procedure insert the audit entry prior to deleting but are there any other recommeded alternative?
If a username was passed as a parameter to the delete stored procedure, is there anyway to get this value in the trigger that's excuted when the record is deleted? I'm just throwing this out there...
i have bind griview dataSource with Store procedure having join of 3 table how can i update this gridview data using stored procedure?
View 5 RepliesI'm using VB.net 2.0 with a SQL server (2005) backend db. I've got a very odd problem. I'm trying to use a stored procedure with a parameter to delete a record from a table. I've tested the stored procedure by running it directly from visual studio and it works fine, but when running it through my application nothing happens. There's no error and it appears to have worked but the record is not deleted.
I've checked permissions on the backend db and giving the network ASPNet account the db owner role has no effect either.
Here's the code, there are 3 layers - the webform code, then the business logic class, then the dataconnection class.
'firstly the original code that is run from the webform when the user selects to delete the record
Partial Public Class NewPerson
Inherits System.Web.UI.Page
Private newConn As New DBConnection
Private currentNewRequest As New NewRequest(newConn)
Protected Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim requestID As Integer = CInt(Me.lblRecordID.Text)
Me.currentNewRequest.newRequestID = requestID
Me.newConn.openConnection()
Me.currentNewRequest.DeleteRecord()
Me.newConn.closeConnection()
End Sub
End Class
'the business logic class that is called to set the parameters etc. The newRequestID integer is set at 19, I have checked this out.
Public Class NewRequest
Private dBConnection As DBConnection
Public newRequestID As Integer
Public Sub New(ByVal dBConnection As DBConnection)
'check params
If dBConnection Is Nothing Then
Throw New ArgumentNullException("dBConnection")
End If
Me.dBConnection = dBConnection
End Sub
Public Sub DeleteRecord()
'This sub deletes a request
With Me.dBConnection
.AddParameter("@newrequestID", SqlDbType.Int, 0, newRequestID)
.ExecNonQuerySP("sp_DeleteNewRequest")
End With
End Sub
End Class
'then the data connection class
Imports System.Data.SqlClient
Public Class DBConnection
Private _ParamList As SqlParameterCollection
Private _MyComm As New SqlCommand
Private _ConnectionStr As String = ConfigurationManager.ConnectionStrings("Conn").ToString
'shared connection
Dim conn As New SqlConnection(_ConnectionStr)
'the parameter is added
Public Sub AddParameter(ByVal ParamName As String, ByVal paramType As Data.SqlDbType, ByVal Paramlength As Int16, ByVal ParamValue As String)
MyComm.Parameters.Add(ParamName, paramType, Paramlength)
If ParamValue = Nothing Or ParamValue = "00:00:00" Or ParamValue = "" Then
_MyComm.Parameters(ParamName).Value = DBNull.Value
Else
_MyComm.Parameters(ParamName).Value = ParamValue
End If
End Sub
'and this is where the stored procedure is supposed to run, no errors are generated
Public Sub ExecNonQuerySP(ByVal SPName As String)
Dim MyAdapter As New SqlDataAdapter(_MyComm)
_MyComm.CommandType = CommandType.StoredProcedure
_MyComm.CommandText = SPName
_MyComm.Connection = conn
If Not _MyTrans Is Nothing Then
_MyComm.Transaction = _MyTrans
End If
Try
_MyComm.ExecuteNonQuery()
Catch ex As Exception
Dim errorMessage As String = ex.GetType.ToString & " " & ex.Message.ToString
System.Web.HttpContext.Current.Session("DBError") = "True"
System.Web.HttpContext.Current.Session("DBEx") = errorMessage
Throw ex
Finally
End Try
End Sub
Public Sub openConnection()
conn.Open()
End Sub
Public Sub closeConnection()
conn.Close()
End Sub
End Class
The stored procedure looks like this:
ALTER PROCEDURE sp_DeleteNewRequest
/*this sp is used to delete a new account request record*/
@newrequestID int
AS
DELETE FROM NewAccountRequest WHERE
NewRequestID = @newrequestID
I have the following stored procedure:
ALTER PROCEDURE Pro_members_Insert
@id int outPut,
@LoginName nvarchar(50),
@Password nvarchar(15),
@FirstName nvarchar(100),
@LastName nvarchar(100),
@signupDate smalldatetime,
@Company nvarchar(100),
@Phone nvarchar(50),
@Email nvarchar(150),
@Address nvarchar(255),
@PostalCode nvarchar(10),
@State_Province nvarchar(100),
@City nvarchar(50),
@countryCode nvarchar(4),
@active bit,
@activationCode nvarchar(50)
AS
declare @usName as varchar(50)
set @usName=''
select @usName=isnull(LoginName,'') from members where LoginName=@LoginName
if @usName <> ''
begin
set @ID=-3
RAISERROR('User Already exist.', 16, 1)
return
end
set @usName=''
select @usName=isnull(email,'') from members where Email=@Email
if @usName <> ''
begin
set @ID=-4
RAISERROR('Email Already exist.', 16, 1)
return
end
declare @MemID as int
select @memID=isnull(max(ID),0)+1 from members
INSERT INTO members (................................
When I run this page, signup.aspx, provide required fields and click submit, the page simply reloads and the database table does not reflect the newly-inserted record. How do I catch the error messages that might be returned from the sproc? how to change signup.aspx so that the insert occurs.
I would like to execute a stored proc that simply updates a record. At this point I would like to keep it parameter less. But in future, I will be adding parameters to the stored proc. Can I simply do it via SQLDataSource? It will save me writing few lines of code to execute stored proc in a traditional ado.net.
View 1 Replies[Code]....
After this and in the same procedure i want to update the inserted or the updated record which occared in the above code with the follwing update statment :
[Code]....
updating mark is completed successfully if the record is existed (Update Case) but if the record does not exist (new record) ... the update of the mark is not occured ..
I am trying to use a stored procedure to insert new records from aspx page. I have created an stored procedure for that and it works fine but I want to display an error message when record exist. It does not display any error message however it does not insert when record exist. How can I display an error message when record exist flag in stored procedure -
[Code]....
I have a database with Pictures in it, they are varbinary(MAX) type, the database is SQL 2005
1. How can I use Linq to SQL to give me the total byte(file size) of a picture stored in a record.
2. How do I get total byte (file size's) of many pictures my a where clause.
I know how to do the where clause just dont know how to add up total byte size of all pictures and or get total size of single picture.
I am trying to update record via stored procedure, but i got error at very start point. Problem is when i click on Edit link button within the Gridview it produce error.
I can populate values from database fine but its produce error when i click on edit link button. see the code below.
[Code]....
[Code]....
I am using paging to my gridview (pagesize=4) . now i am in (X) page and i want to get (X+1) page top record or (X-1)page bottom record , how i can get .
View 2 RepliesI have a delete button bellow my gridview and I want a pop up to show when no record is selected and tell the user to first select a record. The button click event would show the pop up, but my gridview data blanks out.
Here is my code:
[Code]....
I'm very new on VWD, but I got the hang of it for the past 2 weeks(thank you for all the videos posted here in ASP.NET),but I'm really weak on the coding part(vb & c#),except for all the sample shown on the tutorials. Anyways, I have a simple project that
does insert, update & delete to SQL express using the details view. But to complete my project, I need to add a button that will create an event to restore the very last record inserted in SQL and display it back into the details view for minor modification
and nserted again as the newest record with the mod. I'm doing this so user, doesn't need to re-key-in redundant information, like names, original date & time etc, and just make modification on the description of the last record.....
I am counting from a table for that i have written code as below
protected void get_Id_Afterpoint()
{
int counter = 0;
string strSql = "select count(*) as ID from tblEnergy where ID=?";
OdbcCommand com = new OdbcCommand(strSql, con);
com.Parameters.AddWithValue("ID", DropDownList1.SelectedValue);
OdbcDataAdapter oda = new OdbcDataAdapter(com);
DataTable dt = new DataTable();
oda.Fill(dt);
if (dt.Rows.Count == 0)
{
lblID2.Text = "1";
}
else
{
counter = dt.Rows.Count;
counter = counter + 1;
lblID2.Text = Convert.ToString(counter);
}
}
there is no record related to DropDownList1.SelectedValue. but as i am counting if(dt.rows.count) and i put break point on the bolded part it shows 1 record. how it can be possible?
I have the following code which does what it's supposed to do:
objSQLCommand = New SqlCommand("select * from table1", objSQLConnection)
objSQLCommand.Connection.Open()
objSQLDataReader = objSQLCommand.ExecuteReader()[code]....
But I need to loop through the objSQLDataReader 1 more time. How would I do that?
I want users to select a record in the GridView and then have that record open up in the Detailsview. How would I go about getting these two tools to communicate?
View 4 Repliesi have design a web application having suppliers table using SqlDatasource..
i have a master page in my design and other form are bound to a context menu..
Now i have displayed the records in the gridview..all i wanted is after i select a record in the gridview it will display the selected record in detailview from another aspx form..
i was able to create the link to another aspx form but the data that it display is the first data from the gridview not the data that i select.
i have one parent grid on which if user clicks a record ,the child details should get displayed on same page.
for example :
There is one department details table and employees table:
if user selects a record in department details grid,then employees in the selected department should get displayed in the next grid in the same page
How to Call a record on datalist by button click and display record on formview in model using Username
Here is what i tried
<asp:DataList ID="GetMergedAll." runat="server">
<asp:Label ID="Name" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Post" runat="server" Text="Label"></asp:Label>
<asp:LinkButton ID="LinkButton6" runat="server">LinkButton</asp:LinkButton>
</asp:DataList>
protected void Page_Load(object sender, EventArgs e)
[Code] ....
HTML
model here
<asp:FormView ID="Post" runat="server">
<asp:Label ID="Name" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Post" runat="server" Text="Label"></asp:Label>
</asp:FormView>
I was Make code to select top 3 record from db and I wont to enter every record in label or textbox
[Code]....
I am creating an album using the following stored procedure, which returns the primary key for the newly created record:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[fpa_sp_albums_update_insert]
@album_id int,
@album_name nvarchar (50),
@album_descr nvarchar(250),
@album_img_cover_id_FK int,
@album_creation_date date
AS
If @album_id > 0
UPDATE [fpa_albums]
SET
album_name=@album_name,
album_descr= @album_descr,
album_img_cover_id_FK = @album_img_cover_id_FK,
album_creation_date = @album_creation_date
Where ((album_id = @album_id))
Else
INSERT INTO [fpa_albums] (
album_name,
album_descr,
album_img_cover_id_FK,
album_creation_date)
VALUES (
@album_name,
@album_descr,
@album_img_cover_id_FK,
@album_creation_date)
Return SCOPE_IDENTITY();
I execute the above stored procedure using the SQLHELPER. The VB.NET code for the page is as follows:
[Code]....
However, the createdAlbumID always shows -1 instead of the id for the newly created album.
I'm using a details view and a sqldatasource control to populate it. Every once in a while i get an error message because more than one row is returned. How can I have the data display in a gridview instead if more than one row is returned?
View 1 Replies