mycommand.commandtype = CommandType.StoredProcedure ;

解决方案 »

  1.   

    SQL语句:create procedure textBox1(@a int,@b int,@c int,@d int) as insert TABLE_relation_rc(id,roleid,layerid,LayerContent) values(@a,@b,@c,@d)
    go
    只是一条创建存储过程的通用SQL语句。要执行此文本不能使用:
    mycommand.commandtype = CommandType.StoredProcedure ;另外,我没有重现你的错误提示。但当TextBox控件中的文本包含您的SQL语句中的 Go 时,将出现异常。原因是:
    create procedure textBox1(@a int,@b int,@c int,@d int) as insert TABLE_relation_rc(id,roleid,layerid,LayerContent) values(@a,@b,@c,@d)
    go
    在SQL查询分析器中 go 在单独一行中,而在TextBox控件的Text属性中成了:
    create procedure textBox1(@a int,@b int,@c int,@d int) as insert TABLE_relation_rc(id,roleid,layerid,LayerContent) values(@a,@b,@c,@d) go
    此语句有语法问题。就在 go 处。
      

  2.   

    把“go”去掉,然后
    SqlCommand myCommand;
    myCommand=new SqlCommand(textBox.Text,MyConn);                   myCommand.ExecuteNonQuery(); 
    上边是创建存储过程,下边是调用:
    mycommand.commandtype = CommandType.StoredProcedure ;
    myCommand.commandtext="exec textBox1 "+参数
    myCommand.ExecuteNonQuery(); 
    试一试看看。
      

  3.   

    to weifj() 我的go前面是加了回车了,但还是提示系统错误。
      

  4.   

    Dim cmd As New SqlCommand
            cmd.Connection = SqlConnection2
            cmd.CommandType = CommandType.Text
            Dim strStore As String
            strStore = "create procedure textBox1(@a int,@b int,@c int,@d int) " & _
                       " as insert TABLE_relation_rc(id,roleid,layerid,LayerContent) " & _
                       " values(@a,@b,@c,@d)"
            cmd.CommandText = strStore
            SqlConnection2.Open()
            cmd.ExecuteNonQuery()
            SqlConnection2.Close()测试成功