我有一个存储过程执行的时候要输入参数,如果再VB.NET中动态赋值?
SQL可正常执行,执行语句如下execdbo.BomListProcBHT17,1,2,'','','',null,0,0,0,0,0现在我通过VB.NET希望输入的参数...
SQL可正常执行,执行语句如下
exec dbo.BomListProcBHT 17,1,2,'','','',null,0,0,0,0,0
现在我通过VB.NET希望输入的参数通过lable控件的text值实现存储过程参数值的动态赋值,语句如下:
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim con As SqlConnection = New SqlConnection
con.ConnectionString = "Data Source=LZ-PC;Initial Catalog=BHT;User ID=sa;Password=lz5201314"
con.Open()
Dim Comm As SqlCommand
Comm = New SqlCommand("BomListProcBHT", conn)
Comm.CommandType = CommandType.StoredProcedure
Comm.Parameters.Add("@DocID", SqlDbType.Int).Value = DMID.Text
Comm.Parameters.Add("@PrjID", SqlDbType.Int).Value = PJ.Text
Comm.Parameters.Add("@Ver", SqlDbType.Int).Value = REV.Text
Comm.Parameters.Add("@CfgID", SqlDbType.Int).Value = Nothing
Comm.Parameters.Add("@UserID", SqlDbType.Int).Value = Nothing
Comm.Parameters.Add("@ShellRoot", SqlDbType.NVarChar, 260).Value = Nothing
Comm.Parameters.Add("@oViewID", SqlDbType.UniqueIdentifier).Value = Nothing
Comm.Parameters.Add("@bUseLatestVer", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bOneLevel", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bExcludeRootFromResult", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bRespectShowChildrenInResult", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bStripItemTags", SqlDbType.Bit).Value = 0
Dim ds As New DataSet()
Dim ad As New SqlDataAdapter(Comm)
ad.Fill(ds, "BOMJG")
dgvSubItem.DataSource = ds.Tables("BOMJG")
dgvSubItem.Refresh()
con.Close()
Catch ex As Exception
MessageBox.Show("获取BOM错误")
End Try
End Sub
赋值过程中本来存储过程可以在SQL中执行成功例如:( exec dbo.BomListProcBHT 17,1,2,'','','',null,0,0,0,0,0) ,但是如何在VB.NET中给第四个参数赋值=‘’,还有第七个参数赋值=null呢?我赋值为nothing,实现不了,求大神指导。 展开
exec dbo.BomListProcBHT 17,1,2,'','','',null,0,0,0,0,0
现在我通过VB.NET希望输入的参数通过lable控件的text值实现存储过程参数值的动态赋值,语句如下:
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim con As SqlConnection = New SqlConnection
con.ConnectionString = "Data Source=LZ-PC;Initial Catalog=BHT;User ID=sa;Password=lz5201314"
con.Open()
Dim Comm As SqlCommand
Comm = New SqlCommand("BomListProcBHT", conn)
Comm.CommandType = CommandType.StoredProcedure
Comm.Parameters.Add("@DocID", SqlDbType.Int).Value = DMID.Text
Comm.Parameters.Add("@PrjID", SqlDbType.Int).Value = PJ.Text
Comm.Parameters.Add("@Ver", SqlDbType.Int).Value = REV.Text
Comm.Parameters.Add("@CfgID", SqlDbType.Int).Value = Nothing
Comm.Parameters.Add("@UserID", SqlDbType.Int).Value = Nothing
Comm.Parameters.Add("@ShellRoot", SqlDbType.NVarChar, 260).Value = Nothing
Comm.Parameters.Add("@oViewID", SqlDbType.UniqueIdentifier).Value = Nothing
Comm.Parameters.Add("@bUseLatestVer", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bOneLevel", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bExcludeRootFromResult", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bRespectShowChildrenInResult", SqlDbType.Bit).Value = 0
Comm.Parameters.Add("@bStripItemTags", SqlDbType.Bit).Value = 0
Dim ds As New DataSet()
Dim ad As New SqlDataAdapter(Comm)
ad.Fill(ds, "BOMJG")
dgvSubItem.DataSource = ds.Tables("BOMJG")
dgvSubItem.Refresh()
con.Close()
Catch ex As Exception
MessageBox.Show("获取BOM错误")
End Try
End Sub
赋值过程中本来存储过程可以在SQL中执行成功例如:( exec dbo.BomListProcBHT 17,1,2,'','','',null,0,0,0,0,0) ,但是如何在VB.NET中给第四个参数赋值=‘’,还有第七个参数赋值=null呢?我赋值为nothing,实现不了,求大神指导。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询