使用vb.net在sql server中为一个成员插入多个汽车

时间:2014-02-13 11:26:50

标签: sql vb.net vb.net-2010

问题是我想为一个成员添加2行。

感谢您的回复。我有一个成员表和一个membercars表。我需要为一个会员添加多辆车。这是我保存汽车的代码:

Dim cmd As New SqlCommand
cmd.Connection = mcon
cmd.CommandText = "insert into membercars(serial, memberid, make, model, plate, color, tag) values (@serial, @memberid, @make, @model, @plate, @color, @tag);"
cmd.Parameters.AddWithValue("@serial", txtserial.Text)
cmd.Parameters.AddWithValue("@memberid", txtserial.Text)
cmd.Parameters.AddWithValue("@make", txtmake.Text)
cmd.Parameters.AddWithValue("@model", txtmodel.Text)
cmd.Parameters.AddWithValue("@plate", txtplate.Text)
cmd.Parameters.AddWithValue("@color", txtcolor.Text)
cmd.Parameters.AddWithValue("@tag", txttag.Text)
cmd.ExecuteNonQuery()}
fillgrid() 

这是为了节省成员:

cmd.Connection = mcon
strsql = "insert into members "
strsql = strsql & "(name, "
strsql = strsql & "familyname, "
strsql = strsql & "address, "
strsql = strsql & "mobile, "
strsql = strsql & "phone, "
strsql = strsql & "fax, "
strsql = strsql & "email, "
strsql = strsql & "space, "
strsql = strsql & "timezone, "
strsql = strsql & "website) "
strsql = strsql & "values ('" & txtname.Text & "', "
strsql = strsql & "'" & txtfamilyname.Text & "', "
strsql = strsql & "'" & txtaddress.Text & "', "
strsql = strsql & "'" & txtmobile.Text & "', "
strsql = strsql & "'" & txtphone.Text & "', "
strsql = strsql & "'" & txtfax.Text & "', "
strsql = strsql & "'" & txtemail.Text & "', "
strsql = strsql & "'" & txtspace.Text & "', "
strsql = strsql & Val(cmbtimezone.SelectedValue) & ", "
strsql = strsql & "'" & txtwebsite.Text & "') "
strsql += " SELECT IDENT_CURRENT('members')"
' 'strsql += " SELECT @@IDENTITY;"
' '' 
cmd.CommandText = strsql
''cmd.ExecuteNonQuery()
txtsearch.Text = ""
txtserial.Text = cmd.ExecuteScalar().ToString()

再次感谢您的回复:)。

0 个答案:

没有答案