紧急求救~~!!select不出数据,在线等~!
具体代码如下:
类:
Public Sub getdate()
Dim txtSql As String = "select * from supply where goodsName = '" & s_goodsName & "'"
Dim Conn As New SqlConnection("SERVER=(local);database=StockGoods;user id=sa;pwd=123456")
Conn.Open()
Dim cmd As SqlClient.SqlCommand
cmd = New SqlClient.SqlCommand(txtSql, Conn)
Dim DR As SqlDataReader = cmd.ExecuteReader
If DR.Read Then
s_goodsNO = DR(0).ToString()
s_goodsAddress = DR(2).ToString
s_FirstPrice = CType(DR(3), Double)
s_endPrice = CType(DR(4), Double)
End If
DR.Close()
cmd.Dispose()
Conn.Close()
End Sub
窗体:
Public Sub FD()
Dim F_Supply As Supply = New Supply
F_Supply.goodsName = Me.F_NameTxt.Text
Me.F_NoTxt.Text = F_Supply.goodsNO
Me.F_AddressTxt.Text = F_Supply.goodsAddress
Me.F_firstTxt.Text = F_Supply.FirstPrice
Me.F_endTxt.Text = F_Supply.endPrice
F_Supply.getdate()
End Sub
我现在可以把窗体中F_NameTxt.txt的数据传到s_goodsName中,但不知为何,其他几个s_goodsNO、s_goodsAddress、s_FirstPrice、s_endPrice 却还是空值,导致整个查找功能废了~~哪位高手能帮我看看。。。急啊~!!(PS:我正在进行“精确查找”)
在线等回答~~~!
[解决办法]
我猜是不是应该这样呢?Public Sub FD()Dim F_Supply As Supply = New SupplyF_Supply.getdate()F_Supply.goodsName = Me.F_NameTxt.TextMe.F_NoTxt.Text = F_Supply.goodsNOMe.F_AddressTxt.Text = F_Supply.goodsAddressMe.F_firstTxt.Text = F_Supply.FirstPriceMe.F_endTxt.Text = F_Supply.endPriceEnd Sub
[解决办法]
同意楼上,检索数据库过程应先执行才有结果
[解决办法]
Public Sub getdate() dim ds as new datasetDim txtSql As String = "select * from supply where goodsName = '" & s_goodsName & "'" Dim Conn As New SqlConnection("SERVER=(local);database=StockGoods;user id=sa;pwd=123456") Dim cmd As New SqlDataAdapter(txtsql, Conn)cmd.fill(ds,"表名") if ds.tables("表名").rows.count>0 thenwith ds.tables("表名").rows(0) s_goodsNO = .Item("值的字段名").ToString() s_goodsAddress = .Item("值的字段名").ToString () s_FirstPrice = CType(.Item("值的字段名"), Double) s_endPrice = CType(.Item("值的字段名"), Double) end withelseds.dispose()msgbox("没有数据!" + s_goodsname)End If cmd.Dispose() ds.dispose()End Sub