(VB.NET) How to execute Select Max("")
-
iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()
-
iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()
Hi Check this example and apply your code .. You need not use while loop if you are executing ExecuteScalar as it returns one row only. Example from MSDN[^] Hope you got it..
Harini
-
iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()
iam vb6.0 programmer,this code works fine in vb6.0,how to write same code in vb.net
-
iam new to vb.net,iam posting the code i hav written please make modifications where ever neccesary cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as lastfrom EMP_DETAILS where EMP_PLACE='" & ComboBox1.Text & "'" cn.Open() While dr.Read cmd.ExecuteScalar() TextBox1.Text = dr.Item("last") End While cn.Close()
cn.Open() cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as last from EMP_DETAILS where PLACE='" & ComboBox1.Text & "'" dr=cmd.executeREADER While dr.Read TextBox1.Text = dr.Item("last") End While cn.Close() Now Check it
-
cn.Open() cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as last from EMP_DETAILS where PLACE='" & ComboBox1.Text & "'" dr=cmd.executeREADER While dr.Read TextBox1.Text = dr.Item("last") End While cn.Close() Now Check it
hi iqbal ,it is displaying a message "The select statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect".
-
hi iqbal ,it is displaying a message "The select statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect".
try this:
cn.Open() cmd.Connection = cn cmd.CommandText = "select max(EMP_CODE)+1 as [last] from EMP_DETAILS where PLACE='" & ComboBox1.Text & "'" dr=cmd.executeREADER While dr.Read TextBox1.Text = dr.Item("last") End While cn.Close()
Hope this helps you.Peace!