ds.Clear()
' If Module1.sqlconn.State <> ConnectionState.Closed Then
' Module1.sqlconn.Open()
' End If
Dim str As String
str = "insert into 销售表(名称,尺寸,颜色,价格) values ('" & txtShoesID.Text & "','" & CombNoID.SelectedItem & "','" & combColorID.SelectedItem & "','" & txtUnitPrice.Text & "')" '这边的代码不能实现插入呢``??
sqlCmd.Connection = Module1.sqlconn '这边会和下面的起冲突
sqlCmd.CommandType = CommandType.Text
sqlCmd.CommandText = str
' sqlDa.SelectCommand = sqlCmd
' sqlDa.Fill(ds, "销售表")
If Me.ds.Tables.Count <> 0 Then
sqlCmd.Connection = Module1.sqlconn
sqlCmd.CommandType = CommandType.Text
sqlCmd.CommandText = "select * from 销售表 where 名称='" & txtShoesID.Text & "' and 尺寸='" & CombNoID.SelectedItem & "' and 颜色='" & combColorID.SelectedItem & "'"
sqlDa.SelectCommand = sqlCmd
sqlDa.Fill(ds, "销售表")
MessageBox.Show("销售成功", "提示信息")
txtShoesID.Text = ""
CombNoID.Text = ""
combColorID.Text = ""
txtShoesID.Focus()
Else
sqlcmd.CommandText = "select 名称 ,尺寸 ,颜色,价格,数量 from 库存表 where 名称 = @shoesID and 尺寸 = @noID and 颜色 = @colorID"
sqlcmd.Parameters.Add("@shoesID", SqlDbType.VarChar)
sqlcmd.Parameters("@shoesID").Value = Me.txtShoesID.Text
sqlcmd.Parameters.Add("@noID", SqlDbType.Int)
sqlcmd.Parameters("@noID").Value = Me.CombNoID.Text
sqlcmd.Parameters.Add("@colorID", SqlDbType.VarChar)
sqlcmd.Parameters("@colorID").Value = Me.combColorID.SelectedItem
sqlCmd.Connection = Module1.sqlconn'这边会和上面的起冲突
Dim sqlDr As SqlDataReader
Try
Module1.sqlconn.Open()
sqlDr = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlDr.Read Then
Me.txtUnitPrice.Text = sqlDr("价格")
Me.txtStockQuantity.Text = sqlDr("数量")
End If
Catch ex As Exception
MsgBox("发生错误:" & ex.Message)
Finally
If Module1.sqlconn.State <> ConnectionState.Open Then
Module1.sqlconn.Close()
End If
End Try
End Sub
也请高手们能顺便帮我改改代码```把正确的代码发表下```小弟将十分关注的!!!