用SqlCommand能返回一定义变量re1的值吗?
用SqlCommand能返回一定义变量re1的值吗?代码如下,提示不能用return:新增和更新都没问题,但就是想返回一个值,到底是新增的,还是更新的
objConnection = New SqlConnection(sqlstr)
' 打开连接
If objConnection.State <> ConnectionState.Open Then
objConnection.Open()
End If
Dim sql As String
sql = "declare @re1 varchar(20)" + vbCrLf
sql += "if not exists (select * from dbo.idpass where 姓名='" + TextBox1.Text + "')" + vbCrLf
sql += "begin" + vbCrLf
sql += "if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[idpass]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)" + vbCrLf
sql += "CREATE TABLE [dbo].[idpass] (" + vbCrLf
sql += "[姓名] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," + vbCrLf
sql += "[密码] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," + vbCrLf
sql += "[权限] [char] (40) COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY]" + vbCrLf + vbCrLf
sql += "Insert into idpass(姓名,密码,权限) values('" + TextBox1.Text + "','" + TextBox2.Text + "',' ') " + vbCrLf
sql += "set @re1='新增操作人员成功' " + vbCrLf
sql += "end" + vbCrLf
sql += "else" + vbCrLf
sql += "begin" + vbCrLf
sql += "update idpass set 密码 ='" + Trim(TextBox2.Text) + "' where 姓名= '" + Trim(TextBox1.Text) + "'"
sql += "set @re1='操作人员密码修改成功' " + vbCrLf
sql += "end" + vbCrLf
sql += "return @re1"
MsgBox(sql)
Dim cmd As SqlCommand = New SqlCommand(sql, objConnection)