简单的写入SQL的问题

ybcsqq 2006-06-15 02:56:50
代码如下
我的复选框在写入时有误

Dim con As SqlConnection = New SqlConnection("server=dengshutong;database=MYTESTDATABASE;integrated security=SSPI")
Dim insertstr As String = "INSERT INTO dbo.开模型材库 VALUES(" & _
"'" & txtID.Text & "'," & _
"'" & txtName.Text & "'," & _
"'" & txtGender.Text & "'," & _
"'" & txtAddress.Text & "'," & _
"'" & txtZipCode.Text & "'," & _
"'" & DateTimePickerBirthday.Value & "'," & _
"'" & txtMaritalStatus.Text & "'," & _
"'" & DateTimePickerHireDate.Value & "'," & _
NumericUpDownHireSalary.Value & "," & _
NumericUpDownCurrentSalary.Value & "," & _
"'" & DateTimePickerRaiseSalary.Value & "'," & _
> "'" & checkbox1.checked & "'," & _
> "'" & checkbox2.checked & "'," & _
"'" & txtDepartment.Text & "')"
Dim insertcmd As New SqlCommand(insertstr, con)

Try
con.Open()

insertcmd.ExecuteNonQuery()

MessageBox.Show("已经成功新增数据记录。", _
"恭喜您", MessageBoxButtons.OK, _
MessageBoxIcon.Information)

Catch ex As Exception
MessageBox.Show(ex.ToString(), "请注意", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Finally

con.Close()

End Try
...全文
147 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
晓轩 2006-06-15
  • 打赏
  • 举报
回复
好乱啊。不玩了。你倒是把insertstr 帖上来啊。真费劲啊
ybcsqq 2006-06-15
  • 打赏
  • 举报
回复
还是没解决复选框的判断并写入数据表
晓轩 2006-06-15
  • 打赏
  • 举报
回复
insertstr 是这个字符串的值
水如烟 2006-06-15
  • 打赏
  • 举报
回复
这种写法很容易出错的,你可以这样

Dim InsertFormat As String="INSERT INTO table(a,b,c) VALUES('{0}',{1},{2})"
...

Dim InsertString As String=String.Format(InsertFormat,TextBox1.Text,TextBox2.Text,TextBox3.Text)
ybcsqq 2006-06-15
  • 打赏
  • 举报
回复
system.data.sqlclient.sqlexcepion 第一行 'false'附近有语法错误
at system.data.sqlclient.sqlcommand.executenonquery()
as toubiao.form1.button1_click(object sender,eventargs e)
in c:\......
文本框写入没问题呀
晓轩 2006-06-15
  • 打赏
  • 举报
回复
把你的insertstr运行时的值帖上来
ybcsqq 2006-06-15
  • 打赏
  • 举报
回复
还是不行啊
就是system.data.sqlclient.sqlexcepion 'false'附近有语法错误
晓轩 2006-06-15
  • 打赏
  • 举报
回复
我既没有偷鸡又没有摸狗,它咋就不长泥?
晓轩 2006-06-15
  • 打赏
  • 举报
回复
我的信誉分怎么不长啊?
malingxian 2006-06-15
  • 打赏
  • 举报
回复
正解
晓轩 2006-06-15
  • 打赏
  • 举报
回复
Dim insertstr As String = "INSERT INTO dbo.开模型材库 VALUES(" & _
改:
Dim insertstr As String = "INSERT INTO dbo.开模型材库(字段名,字段名。。。) VALUES(" & _

16,554

社区成员

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

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