R
rasol
Guest
hi Friends .
i am a newer in vb 2010 .
i have a problem.
I want to insert into jj table Withthree fields as (id int identity(1,1),name nvarchar(50),serial nvarchar(50)) so that ,
the serial number in serial field with each time click ,insert and
move forward one record.
my code is this :
Continue reading...
i am a newer in vb 2010 .
i have a problem.
I want to insert into jj table Withthree fields as (id int identity(1,1),name nvarchar(50),serial nvarchar(50)) so that ,
the serial number in serial field with each time click ,insert and
move forward one record.
my code is this :
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer = 0
Dim myreader As SqlDataReader
Dim conn as sqlconnection
Dim cmd as sqlcommand
conn = New SqlConnection("Data source=Accounting-pc;initial catalog=rasol;integrated security=sspi;")
conn.Open()
cmd = New SqlCommand("select max(serial) from jj", conn)
cmd.CommandType = CommandType.Text
myreader = cmd.ExecuteReader()
If myreader.HasRows Then
Do While myreader.Read()
i = i + 1
Loop
Else
i = 1
End if
myreader.Close()
cmd = New SqlCommand("insert into jj(name,serial) values (" + TextBox1.Text + "," + CStr(i) + ")", conn)
cmd.CommandType = CommandType.Text
cmd.Parameters.AddWithValue("name", TextBox1.Text)
cmd.ExecuteNonQuery()
conn.Close()
conn = Nothing
End Sub
please help me.
when I run my program, it dose not work properly
best Wishes.
Continue reading...