用的VB,在书上看,可以用DataRow来做,但是我想直接用SQL进行,可以吗?哪种比较好?
我用SQL这样写的,
dim upcommand as New SqlCommand(Insert into infom(No,name,age) Values("&no&","&name&","&age&")
upcommand.Connection.Open()
upcommand.ExecuteNonQuery()
总说编译错误呀,怎么回事?语句应该怎么写?
小妹谢过了~

解决方案 »

  1.   

    dim no as string = "123"
    dim name as string = "aaaaaa"
    dim age as string = "18"
    dim sql as string = "Insert into infom(No,name,age) Values('" & no & "','" & name & "','" & age & "'"
    dim upcommand as New SqlCommand(sql)
    '......
      

  2.   


    string strsql = "Insert into infom(No,name,age) Values ('"&no&"','"&name&"','"&age&"')"
    dim upcommand as New SqlCommand(strsql)
      

  3.   

    照楼上的改了,可是说
    运算符“&”不是为类型“String”和“System.Web.UI.WebControls.TextBox”定义的 
    怎么办??
      

  4.   

    dim upcommand as New SqlCommand("Insert into infom(No,name,age) Values("&no&","&name&","&age&")"
    upcommand.Connection.Open()
    upcommand.ExecuteNonQuery()
      

  5.   

    换了种方法,还是有错,说是“未将对象引用设置到对象的实例”
    怎么回事?我晕呀……
    代码如下:
    dim upConnect as string
    upConnect="database=myexp;server=localhost;uid=sa;pwd=;"
    dim upConnection as New SqlConnection(upConnect)
    dim strsql as string
    strsql="SELECT * FROM infom"
    dim upcommand as New SqlCommand(strsql,upConnection)
    dim upDataSet as New DataSet()
    dim upAdapter as SqlDataAdapter
    upAdapter.Fill(upDataSet,"infom")
    dim upTable as DataTable
    upTable=upDataSet.Tables("infom")
    dim upNewRow as DataRow
    upNewRow=upTable.NewRow()
    upNewRow("No")=6
    upNewRow("name")="Innsbruck"
    upNewRow("age")=32
    upTable.Rows.Add(upNewRow)
    dim upBuilder as SqlCommandBuilder
    upBuilder= New SqlCommandBuilder(upAdapter)
    upAdapter.InsertCommand = upBuilder.GetInsertCommand()
    upAdapter.Update(upDataSet,"infom")
    upcommand.Connection.Open()
    upcommand.ExecuteNonQuery()
      

  6.   

    string strsql = "Insert into infom(No,name,age) Values ('"&no&"','"&name&"','"&age&"')"
    dim upcommand as New SqlCommand(strsql)
    c#裡應該改&為+
      

  7.   

    我用的是VB呀,就是&吧
    现在提示的错误是“ 在调用“Fill”前,SelectCommand 属性尚未初始化。”
    怎么回事?