Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

record data from gridview

This is the case, when i click the submit button inside my form, all the data filled will be inserted into the database. inside my form i have add a gridview with select option, when user click the select option, the selected field will be displayed inside listbox and recorded inside database. The problem now is when i select multiple field, the selected fields displayed inside listbox but ONLY the 1st selected field being recorder inside database. Means that for example i have select A,B and C, the listbox displayed A,B,C but only A being recorded. Can somebody help me with this? Thanks

Below is my Code :

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim myConnection As SqlConnection = New SqlConnection()
myConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()
Dim myCommand As SqlCommand = New SqlCommand()
myCommand.CommandText = "insertCustomer"
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Connection = myConnection

Dim c1 As SqlParameter = New SqlParameter()
c1.ParameterName = "@cusname"
c1.Value = nametext.Text
c1.SqlDbType = System.Data.SqlDbType.Char
myCommand.Parameters.Add(c1)

Dim c2 As SqlParameter = New SqlParameter()
c2.ParameterName = "@cusic"
c2.Value = ictext.Text
c2.SqlDbType = System.Data.SqlDbType.Int
myCommand.Parameters.Add(c2)

Dim c3 As SqlParameter = New SqlParameter()
c3.ParameterName = "@cusadd"
c3.Value = addtext.Text
c3.SqlDbType = System.Data.SqlDbType.VarChar
myCommand.Parameters.Add(c3)

Dim c4 As SqlParameter = New SqlParameter()
c4.ParameterName = "@resname"
c4.Value = menugrid.Rows(menugrid.SelectedIndex).Cells(1).Text
c4.SqlDbType = System.Data.SqlDbType.NChar
myCommand.Parameters.Add(c4)

Dim c5 As SqlParameter = New SqlParameter()
c5.ParameterName = "@price"
c5.Value = menugrid.Rows(menugrid.SelectedIndex).Cells(2).Text
c5.SqlDbType = System.Data.SqlDbType.Money
myCommand.Parameters.Add(c5)

Dim c6 As SqlParameter = New SqlParameter()
c6.ParameterName = "@tmenu"
c6.Value = menugrid.Rows(menugrid.SelectedIndex).Cells(3).Text
c6.SqlDbType = System.Data.SqlDbType.VarChar
myCommand.Parameters.Add(c6)

myConnection.Open()

myCommand.ExecuteNonQuery()
Server.Transfer("done.aspx")

myConnection.Close()

End Sub
[2903 byte] By [Zouve] at [2007-11-11 9:57:26]