问题描述
我的程序是要往数据库中添加数据但是始终添加不进去下面是存储过程ALTERPROCEDUREdbo.StoredProcedure1@idchar(8)output,@namevarchar(20)outputASinsertintoStudents(S_id,S_name)values(@id,@name)RETURN下面是程序privatevoidbutton1_Click(objectsender,EventArgse){SqlConnectionconn=newSqlConnection(Properties.Settings.Default.mydatabase_DataConnectionString);SqlCommandcmd=newSqlCommand("StoredProcedure1",conn);cmd.CommandType=CommandType.StoredProcedure;cmd.Parameters.AddWithValue("@id",05023111);cmd.Parameters.AddWithValue("@name","计科");try{conn.Open();cmd.CommandTimeout=60;inta=cmd.ExecuteNonQuery();cmd.Parameters["@name"].Direction=ParameterDirection.Output;cmd.Parameters["@id"].Direction=ParameterDirection.Output;MessageBox.Show(string.Format("{0},{1}",cmd.Parameters["@id"].Value,cmd.Parameters["@name"].Value));}catch(Exceptionerr){MessageBox.Show(err.Message);}finally{MessageBox.Show(Convert.ToString(a));conn.Close();}}