SQL update current ID of record?http://forums.asp.net/t/1773669.aspx/1?SQL+update+current+ID+of+record+Sat, 25 Feb 2012 08:06:21 -050017736694850372http://forums.asp.net/p/1773669/4850372.aspx/1?SQL+update+current+ID+of+record+SQL update current ID of record? <p>Hi,</p> <p>I have a sript that updates a raw in my database, but after selected raw is updated I need to now ID of that raw, please help, my code is like this:</p> <p>Dim connectionString As String = WebConfigurationManager.ConnectionStrings(&quot;dbDatabase&quot;).ConnectionString<br> Dim updateSQL As String = &quot;UPDATE tblUsers SET LEVET=@LEVEL WHERE CODE = '&quot; &amp; strCode &amp; &quot; '&quot;<br> Dim con As New SqlConnection(connectionString)<br> Dim cmd As New SqlCommand(updateSQL, con)</p> <p>cmd.Parameters.AddWithValue(&quot;@LEVEL&quot;, 5)Dim added As Integer = 0</p> <p>Try<br> con.Open()<br> added = cmd.ExecuteNonQuery()</p> <p>Response.Redirect(&quot;~\korisnicka_stranica.aspx&quot;)<br> Catch err As Exception<br> &nbsp; &nbsp;lblError.Text &amp;= &quot;Error inserting record. (subAdd)&quot;<br> &nbsp; &nbsp;lblError.Text &amp;= err.Message<br> Finally<br> con.Close()<br> End Try</p> 2012-02-25T06:55:07-05:004850405http://forums.asp.net/p/1773669/4850405.aspx/1?Re+SQL+update+current+ID+of+record+Re: SQL update current ID of record? <p>write one more select statement like 'select Id from tblUsers where CODe = strCode'...that will return you ID...and then you can use ExecuteScalar to catch the ID in C# -&nbsp;<a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx">http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx</a>&nbsp;</p> <p>Thanks,</p> 2012-02-25T08:06:21-05:00