G
Guest
Can someone tell me a better way or give me a link that shows a better way to
create large numbers of SQL parameters...
Example... A better way to write this code!
<code>
Sub UploadData(ByVal sender As Object, ByVal e As EventArgs)
Dim MyConn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("AddMenu", MyConn)
cmd.CommandType = CommandType.StoredProcedure
Dim Dateparam As New SqlParameter("@Date", SqlDbType.NVarChar, 255)
' Dim i As Integer
' For i = 0 To 11
Dim Item1param As New SqlParameter("@mItem1", SqlDbType.NVarChar, 255)
Dim Item2param As New SqlParameter("@mItem2", SqlDbType.NVarChar, 255)
Dim Item3param As New SqlParameter("@mItem3", SqlDbType.NVarChar, 255)
Dim Item4param As New SqlParameter("@mItem4", SqlDbType.NVarChar, 255)
Dim Item5param As New SqlParameter("@mItem5", SqlDbType.NVarChar, 255)
Dim Item6param As New SqlParameter("@mItem6", SqlDbType.NVarChar, 255)
Dim Item7param As New SqlParameter("@mItem7", SqlDbType.NVarChar, 255)
Dim Item8param As New SqlParameter("@mItem8", SqlDbType.NVarChar, 255)
Dim Item9param As New SqlParameter("@mItem9", SqlDbType.NVarChar, 255)
Dim Item10param As New SqlParameter("@mItem10", SqlDbType.NVarChar,
255)
Dim Price1param As New SqlParameter("@mPrice1", SqlDbType.NVarChar,
255)
Dim Price2param As New SqlParameter("@mPrice2", SqlDbType.NVarChar,
255)
Dim Price3param As New SqlParameter("@mPrice3", SqlDbType.NVarChar,
255)
Dim Price4param As New SqlParameter("@mPrice4", SqlDbType.NVarChar,
255)
Dim Price5param As New SqlParameter("@mPrice5", SqlDbType.NVarChar,
255)
Dim Price6param As New SqlParameter("@mPrice6", SqlDbType.NVarChar,
255)
Dim Price7param As New SqlParameter("@mPrice7", SqlDbType.NVarChar,
255)
Dim Price8param As New SqlParameter("@mPrice8", SqlDbType.NVarChar,
255)
Dim Price9param As New SqlParameter("@mPrice9", SqlDbType.NVarChar,
255)
Dim Price10param As New SqlParameter("@mPrice10",
SqlDbType.NVarChar, 255)
Dateparam.Value = tbDate.Text
Item1param.Value = tbMenuItem1.Text
Item2param.Value = tbMenuItem2.Text
Item3param.Value = tbMenuItem3.Text
Item4param.Value = tbMenuItem4.Text
Item5param.Value = tbMenuItem5.Text
Item6param.Value = tbMenuItem6.Text
Item7param.Value = tbMenuItem7.Text
Item8param.Value = tbMenuItem8.Text
Item9param.Value = tbMenuItem9.Text
Item10param.Value = tbMenuItem10.Text
Price1param.Value = tbMenuPrice1.Text
Price2param.Value = tbMenuPrice2.Text
Price3param.Value = tbMenuPrice3.Text
Price4param.Value = tbMenuPrice4.Text
Price5param.Value = tbMenuPrice5.Text
Price6param.Value = tbMenuPrice6.Text
Price7param.Value = tbMenuPrice7.Text
Price8param.Value = tbMenuPrice8.Text
Price9param.Value = tbMenuPrice9.Text
Price10param.Value = tbMenuPrice10.Text
cmd.Parameters.Add(Dateparam)
cmd.Parameters.Add(Item1param)
cmd.Parameters.Add(Item2param)
cmd.Parameters.Add(Item3param)
cmd.Parameters.Add(Item4param)
cmd.Parameters.Add(Item5param)
cmd.Parameters.Add(Item6param)
cmd.Parameters.Add(Item7param)
cmd.Parameters.Add(Item8param)
cmd.Parameters.Add(Item9param)
cmd.Parameters.Add(Item10param)
cmd.Parameters.Add(Price1param)
cmd.Parameters.Add(Price2param)
cmd.Parameters.Add(Price3param)
cmd.Parameters.Add(Price4param)
cmd.Parameters.Add(Price5param)
cmd.Parameters.Add(Price6param)
cmd.Parameters.Add(Price7param)
cmd.Parameters.Add(Price8param)
cmd.Parameters.Add(Price9param)
cmd.Parameters.Add(Price10param)
' Next
MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
End Sub
create large numbers of SQL parameters...
Example... A better way to write this code!
<code>
Sub UploadData(ByVal sender As Object, ByVal e As EventArgs)
Dim MyConn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("AddMenu", MyConn)
cmd.CommandType = CommandType.StoredProcedure
Dim Dateparam As New SqlParameter("@Date", SqlDbType.NVarChar, 255)
' Dim i As Integer
' For i = 0 To 11
Dim Item1param As New SqlParameter("@mItem1", SqlDbType.NVarChar, 255)
Dim Item2param As New SqlParameter("@mItem2", SqlDbType.NVarChar, 255)
Dim Item3param As New SqlParameter("@mItem3", SqlDbType.NVarChar, 255)
Dim Item4param As New SqlParameter("@mItem4", SqlDbType.NVarChar, 255)
Dim Item5param As New SqlParameter("@mItem5", SqlDbType.NVarChar, 255)
Dim Item6param As New SqlParameter("@mItem6", SqlDbType.NVarChar, 255)
Dim Item7param As New SqlParameter("@mItem7", SqlDbType.NVarChar, 255)
Dim Item8param As New SqlParameter("@mItem8", SqlDbType.NVarChar, 255)
Dim Item9param As New SqlParameter("@mItem9", SqlDbType.NVarChar, 255)
Dim Item10param As New SqlParameter("@mItem10", SqlDbType.NVarChar,
255)
Dim Price1param As New SqlParameter("@mPrice1", SqlDbType.NVarChar,
255)
Dim Price2param As New SqlParameter("@mPrice2", SqlDbType.NVarChar,
255)
Dim Price3param As New SqlParameter("@mPrice3", SqlDbType.NVarChar,
255)
Dim Price4param As New SqlParameter("@mPrice4", SqlDbType.NVarChar,
255)
Dim Price5param As New SqlParameter("@mPrice5", SqlDbType.NVarChar,
255)
Dim Price6param As New SqlParameter("@mPrice6", SqlDbType.NVarChar,
255)
Dim Price7param As New SqlParameter("@mPrice7", SqlDbType.NVarChar,
255)
Dim Price8param As New SqlParameter("@mPrice8", SqlDbType.NVarChar,
255)
Dim Price9param As New SqlParameter("@mPrice9", SqlDbType.NVarChar,
255)
Dim Price10param As New SqlParameter("@mPrice10",
SqlDbType.NVarChar, 255)
Dateparam.Value = tbDate.Text
Item1param.Value = tbMenuItem1.Text
Item2param.Value = tbMenuItem2.Text
Item3param.Value = tbMenuItem3.Text
Item4param.Value = tbMenuItem4.Text
Item5param.Value = tbMenuItem5.Text
Item6param.Value = tbMenuItem6.Text
Item7param.Value = tbMenuItem7.Text
Item8param.Value = tbMenuItem8.Text
Item9param.Value = tbMenuItem9.Text
Item10param.Value = tbMenuItem10.Text
Price1param.Value = tbMenuPrice1.Text
Price2param.Value = tbMenuPrice2.Text
Price3param.Value = tbMenuPrice3.Text
Price4param.Value = tbMenuPrice4.Text
Price5param.Value = tbMenuPrice5.Text
Price6param.Value = tbMenuPrice6.Text
Price7param.Value = tbMenuPrice7.Text
Price8param.Value = tbMenuPrice8.Text
Price9param.Value = tbMenuPrice9.Text
Price10param.Value = tbMenuPrice10.Text
cmd.Parameters.Add(Dateparam)
cmd.Parameters.Add(Item1param)
cmd.Parameters.Add(Item2param)
cmd.Parameters.Add(Item3param)
cmd.Parameters.Add(Item4param)
cmd.Parameters.Add(Item5param)
cmd.Parameters.Add(Item6param)
cmd.Parameters.Add(Item7param)
cmd.Parameters.Add(Item8param)
cmd.Parameters.Add(Item9param)
cmd.Parameters.Add(Item10param)
cmd.Parameters.Add(Price1param)
cmd.Parameters.Add(Price2param)
cmd.Parameters.Add(Price3param)
cmd.Parameters.Add(Price4param)
cmd.Parameters.Add(Price5param)
cmd.Parameters.Add(Price6param)
cmd.Parameters.Add(Price7param)
cmd.Parameters.Add(Price8param)
cmd.Parameters.Add(Price9param)
cmd.Parameters.Add(Price10param)
' Next
MyConn.Open()
cmd.ExecuteNonQuery()
MyConn.Close()
End Sub