有人帮帮我么! 我想做个数据库,代码是和书上的改的,但是就是不能存贮!有人帮忙么,都一天了不知道什么地方错了。 代码如下: public bool InsertSchedule(ref SqlConnection myConn) { SqlCommand cmd_InsertNewSchedule = new SqlCommand("SD",myConn); cmd_InsertNewSchedule.CommandType = CommandType.StoredProcedure; cmd_InsertNewSchedule.Parameters.Add("@c_id", c_id); cmd_InsertNewSchedule.Parameters.Add("@address", address);//------------ cmd_InsertNewSchedule.Parameters.Add("@tel", tel); cmd_InsertNewSchedule.Parameters.Add("@p_time", p_time); cmd_InsertNewSchedule.Parameters.Add("@out_water_num", out_water_num); cmd_InsertNewSchedule.Parameters.Add("@back_barrel_num", back_barrel_num);//--------- cmd_InsertNewSchedule.Parameters.Add("@money_metion", money_metion); cmd_InsertNewSchedule.Parameters.Add("@man_out_water", man_out_water); cmd_InsertNewSchedule.Parameters.Add("@remnant_water", remnant_water);//--------- cmd_InsertNewSchedule.Parameters.Add("@stock_water", stock_water); cmd_InsertNewSchedule.Parameters.Add("@man_stock_water", man_stock_water); cmd_InsertNewSchedule.Parameters.Add("@back_up", back_up); try { cmd_InsertNewSchedule.ExecuteNonQuery(); } catch { return false; } return true; } 主要的程序 private void button2_Click(object sender, System.EventArgs e) { if((textBox1.Text == "")||(textBox2.Text == "")||(textBox3.Text == "")||(textBox4.Text == "")||(textBox5.Text == "")||(comboBox1.Text == "")||(comboBox2.Text == "")||(comboBox3.Text == "")) { MessageBox.Show("标题不能为空!","Error"); return; }
int c_id = Int32.Parse(textBox1.Text.Trim() );// 1 //int fff=c_id; //Int32.Parse(taskTypeListbox.SelectedValue.ToString()); string address = textBox2.Text.Trim();// 2 string tel = textBox3.Text.Trim(); // 3 DateTime p_time = DateTime.Parse(dateTimePicker1.Text.Trim());// 4 int out_water_num = Int32.Parse(textBox4.Text.Trim());// 5 int back_barrel_num=Int32.Parse(textBox5.Text.Trim());// 6 string money_metion = comboBox1.Text.Trim();// 7 //int Type = Int32.Parse(taskTypeListbox.SelectedValue.ToString()); string man_out_water= comboBox2.Text.Trim();// 8 int remnant_water = 3;//Int32.Parse(textBox1.Text.Trim());// 9 //int stock_water=nstock_water; int stock_water= 3;//Int32.Parse(textBox1.Text.Trim());// 10 string man_stock_water=comboBox3.Text.Trim();// 11 string back_up=textBox13.Text.Trim();// 12 label44.Text=back_up+man_stock_water+c_id*100+address+p_time; waters Newwaters = new waters(); Newwaters.SetSchedule(c_id , address,tel, p_time, out_water_num,back_barrel_num, money_metion, man_out_water, remnant_water,stock_water,man_stock_water,back_up); // int nc_id , string saddress, int stel, DateTime dp_time, int dout_water_num,int dback_barrel_num ,string nmoney_metion, string nman_out_water, int nremnant_water,int nstock_water,string nman_stock_water,string dback_up)
if(!Newwaters.InsertSchedule(ref myConn)) { MessageBox.Show("添加失败!","Error"); } else { MessageBox.Show("添加成功!","OK"); Init_AddSchedulePage(); }
return;
} 存储过程 CREATE PROCEDURE SD ( @c_id bigint, @address varchar(8000), @tel varchar(50), @p_time datetime, @out_water_num int, @back_barrel_num int, @money_metion varchar(100), @man_out_water varchar(100), @remnant_water int, @stock_water int, @man_stock_water varchar(100), @back_up varchar(100) ) AS INSERT INTO SDS ( c_id, address, tel, p_time, out_water_num, back_barrel_num, money_metion, man_out_water, remnant_water, stock_water, man_stock_water, back_up ) VALUES ( @c_id, @address, @tel, @p_time, @out_water_num, @back_barrel_num, @money_metion, @man_out_water, @remnant_water, @stock_water, @man_stock_water, @back_up ) RETURN GO