紧急求救~~!!select不出数据,在线等~!

terry183 2008-09-04 10:46:05
具体代码如下:

类:
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:我正在进行“精确查找”)
在线等回答~~~!
...全文
125 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
terry183 2008-09-04
  • 打赏
  • 举报
回复
Public Class Supply 
Private s_goodsNO As String = ""
Private s_goodsName As String = ""
Private s_goodsAddress As String = ""
Private s_FirstPrice As Double = 0
Private s_endPrice As Double = 0

Public Property goodsNO() As String
Get
Return s_goodsNO
End Get
Set(ByVal value As String)
s_goodsNO = value
End Set
End Property
Public Property goodsName() As String
Get
Return s_goodsName
End Get
Set(ByVal value As String)
s_goodsName = value
End Set
End Property
Public Property goodsAddress() As String
Get
Return s_goodsAddress
End Get
Set(ByVal value As String)
s_goodsAddress = value
End Set
End Property
Public Property FirstPrice() As Double
Get
Return s_FirstPrice
End Get
Set(ByVal value As Double)
s_FirstPrice = value
End Set
End Property
Public Property endPrice() As Double
Get
Return s_endPrice
End Get
Set(ByVal value As Double)
s_endPrice = value
End Set
End Property


Private Function GetSqlString(ByVal iType As Integer) As String

Dim Result As String = ""
Select Case iType
Case 0 : Result = "Insert into Supply (goodsNO,goodsName,goodsAddress,FirstPrice,endPrice) values ('" & s_goodsNO & "','" & s_goodsName & "','" & s_goodsAddress & "'," & s_FirstPrice & "," & s_endPrice & ")"
Case 1 : Result = "Update Supply Set goodsName = '" & s_goodsName & "',goodsAddress='" & s_goodsAddress & "',FirstPrice = " & s_FirstPrice & ",endPrice = " & s_endPrice & ",goodsNO = '" & s_goodsNO & "'"
Case 2 : Result = "Delete From Supply where goodsName = '" & s_goodsName & "'"
Case Else : Result = ""
End Select
Return Result
End Function
terry183 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 ZengHD 的回复:]
你传进去的是goodsName ,使用的是s_goodsName
使用了属性?贴出代码
[/Quote]

goodsName 是SQL中的字段
terry183 2008-09-04
  • 打赏
  • 举报
回复
Public Class Supply
Private s_goodsNO As String = ""
Private s_goodsName As String = ""
Private s_goodsAddress As String = ""
Private s_FirstPrice As Double = 0
Private s_endPrice As Double = 0

Public Property goodsNO() As String
Get
Return s_goodsNO
End Get
Set(ByVal value As String)
s_goodsNO = value
End Set
End Property
Public Property goodsName() As String
Get
Return s_goodsName
End Get
Set(ByVal value As String)
s_goodsName = value
End Set
End Property
Public Property goodsAddress() As String
Get
Return s_goodsAddress
End Get
Set(ByVal value As String)
s_goodsAddress = value
End Set
End Property
Public Property FirstPrice() As Double
Get
Return s_FirstPrice
End Get
Set(ByVal value As Double)
s_FirstPrice = value
End Set
End Property
Public Property endPrice() As Double
Get
Return s_endPrice
End Get
Set(ByVal value As Double)
s_endPrice = value
End Set
End Property


Private Function GetSqlString(ByVal iType As Integer) As String

Dim Result As String = ""
Select Case iType
Case 0 : Result = "Insert into Supply (goodsNO,goodsName,goodsAddress,FirstPrice,endPrice) values ('" & s_goodsNO & "','" & s_goodsName & "','" & s_goodsAddress & "'," & s_FirstPrice & "," & s_endPrice & ")"
Case 1 : Result = "Update Supply Set goodsName = '" & s_goodsName & "',goodsAddress='" & s_goodsAddress & "',FirstPrice = " & s_FirstPrice & ",endPrice = " & s_endPrice & ",goodsNO = '" & s_goodsNO & "'"
Case 2 : Result = "Delete From Supply where goodsName = '" & s_goodsName & "'"
Case Else : Result = ""
End Select
Return Result
End Function


你指的应该就是这些吧~~谢谢了~~
ZengHD 2008-09-04
  • 打赏
  • 举报
回复
你传进去的是goodsName ,使用的是s_goodsName
使用了属性?贴出代码
terry183 2008-09-04
  • 打赏
  • 举报
回复
Private s_goodsNO As String = ""
Private s_goodsName As String = ""
Private s_goodsAddress As String = ""
Private s_FirstPrice As Double = 0
Private s_endPrice As Double = 0

我想。。。应该不会是这些有问题吧~~~
terry183 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ZengHD 的回复:]
引用 3 楼 terry183 的回复:
不是~~如果这样的话,就连F_NameTxt.txt的数据也传不到s_goodsName了~~s_goodsName为""

难道你就不会变通一下下啊

F_Supply.goodsName = Me.F_NameTxt.Text
F_Supply.getdate()
[/Quote]

已经变过了~~大哥
ZengHD 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 terry183 的回复:]
不是~~如果这样的话,就连F_NameTxt.txt的数据也传不到s_goodsName了~~s_goodsName为""
[/Quote]
难道你就不会变通一下下啊

F_Supply.goodsName = Me.F_NameTxt.Text
F_Supply.getdate()
terry183 2008-09-04
  • 打赏
  • 举报
回复
不是~~如果这样的话,就连F_NameTxt.txt的数据也传不到s_goodsName了~~s_goodsName为""
blues_zhao_yang 2008-09-04
  • 打赏
  • 举报
回复
同意楼上,检索数据库过程应先执行才有结果
ZengHD 2008-09-04
  • 打赏
  • 举报
回复
我猜是不是应该这样呢?
Public Sub FD()
Dim F_Supply As Supply = New Supply
F_Supply.getdate()
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
End Sub
terry183 2008-09-04
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 htpower 的回复:]
VB.NET code
Public Sub getdate()
dim ds as new dataset
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")
Dim cmd As New SqlDataAdapter(txtsql, Conn)
cmd.fill(ds,"表名")
if ds.tables("表名").rows.count>0 then
with ds.tables("表名").rows(0)
s_goodsNO = .Ite…
[/Quote]

问题解决~~~!!还多谢11楼教我用上dataset~~!!

原来还要在这里改一下(感谢2楼的提示)
Dim F_Supply As Supply = New Supply
F_Supply.goodsName = Me.F_NameTxt.Text
F_Supply.getdate()
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
terry183 2008-09-04
  • 打赏
  • 举报
回复
会否是我的SQL2005设置有问题?!
terry183 2008-09-04
  • 打赏
  • 举报
回复
11楼朋友的代码验证过没的?
我对dataset方法的点生疏,我照你的说话做了,可还是不行,而且没的弹出
msgbox("没有数据!" + s_goodsname)提示,我真的晕了。。。
htpower 2008-09-04
  • 打赏
  • 举报
回复

Public Sub getdate()
dim ds as new dataset
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")
Dim cmd As New SqlDataAdapter(txtsql, Conn)
cmd.fill(ds,"表名")
if ds.tables("表名").rows.count>0 then
with ds.tables("表名").rows(0)
s_goodsNO = .Item("值的字段名").ToString()
s_goodsAddress = .Item("值的字段名").ToString ()
s_FirstPrice = CType(.Item("值的字段名"), Double)
s_endPrice = CType(.Item("值的字段名"), Double)
end with
else
ds.dispose()
msgbox("没有数据!" + s_goodsname)
End If
cmd.Dispose()
ds.dispose()
End Sub


这样行不?

16,717

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧