当前位置:编程学习 > C#/ASP.NET >>

帮看下我的调用存储过程错在哪里? vb.net 和 C#的语法是一样的。

Public Conn As SqlConnection = New SqlConnection("Data Source=192.168.10.1;Initial Catalog=RBS;Persist Security Info=True;User ID=sa;Password=barcode;Connect Timeout=5") Public comm As New SqlCommand() Public Function UpdateBarn(ByVal barcode As String, ByVal state As Integer) As Boolean comm = New SqlCommand("UpdateBarn", Conn) comm.CommandType = CommandType.StoredProcedure comm.Parameters.Add("@barcode", SqlDbType.NVarChar, 50).Value = barcode comm.Parameters.Add("@state", SqlDbType.Int, 1).Value = state Try comm.ExecuteNonQuery() Return True Catch FileSystem.FileCopy("d:\Test.txt", "lpt1") '发送文件到并口,以报警 TextBox1.Clear() TextBox1.ReadOnly = False MsgBox("网络连接超时,请检查网络设置!", MsgBoxStyle.Question, "UpdateBarn错误") Return False Exit Function End Try End Function
追问:原来我的代码是有conn.open的,后来删掉了, 效果是一样的。
答案:你忘记写更新语句了    
Public Function UpdateBarn(ByVal barcode As String, ByVal state As Integer) As Boolean
        Dim SqlStr As String = "Update RBS.dbo.Tabbarcode Set barcode=(@barcode),state=(@state) " '注意Tabbarcode 改为你存储条码的表名
        comm = New SqlClient.SqlCommand(SqlStr, Conn)
        comm.CommandType = CommandType.StoredProcedure
        comm.Parameters.Add("@barcode", SqlDbType.NVarChar, 50).Value = barcode
        comm.Parameters.Add("@state", SqlDbType.Int, 1).Value = state
        Try
            comm.ExecuteNonQuery()
            Return True
        Catch
            FileSystem.FileCopy("d:\Test.txt", "lpt1") '发送文件到并口,以报警
            TextBox1.Clear()
            TextBox1.ReadOnly = False
            MsgBox("网络连接超时,请检查网络设置!", MsgBoxStyle.Question, "UpdateBarn错误")
            Return False
            Exit Function
        End Try
    End Function
其他:我只会c#,不会vb
但我觉得你少了
conn.Open()和conn.Close() 提示什么错误
没有说出提示错误不好判断 

上一个:vb.net 中datagridview内数据修改后保存代码怎么写
下一个:用vb.net 创建.bat文件 可总是提示UnauthorizedAccessException异常 访问拒绝

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,