标题:C#操作SQL存贮数据,遇到麻烦了,希望有人帮我!
取消只看楼主
jianfeixu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-1-24
 问题点数:0 回复次数:4 
C#操作SQL存贮数据,遇到麻烦了,希望有人帮我!

有人帮帮我么! 我想做个数据库,代码是和书上的改的,但是就是不能存贮!有人帮忙么,都一天了不知道什么地方错了。 代码如下: 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

搜索更多相关主题的帖子: SQL cmd 数据库 存贮 
2005-01-24 15:15
jianfeixu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-1-24
得分:0 

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); 不好意思太乱了,是这样的: public void SetSchedule(int nc_id , string saddress, string 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) { c_id = nc_id ;// address = saddress;// tel = stel; p_time = dp_time; out_water_num = dout_water_num;// back_barrel_num=dback_barrel_num;// money_metion = nmoney_metion; man_out_water = nman_out_water; remnant_water = nremnant_water; stock_water=nstock_water; man_stock_water=nman_stock_water; back_up=dback_up; Checkaddress(); Checkmoney_metion(); Checkman_out_water(); Checkman_stock_wate();

}

2005-01-24 16:36
jianfeixu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-1-24
得分:0 
谢谢各位的线索,我终于知道是什么地方出错了,是SDS,我把自己建的表的名字搞错了,太谢谢各位了!程序通的那一瞬间我充满了对你们的感激!谢谢!谢谢!!
2005-01-24 16:43
jianfeixu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-1-24
得分:0 
...我,没有注意到,仔细看,真的是!!以后我可能会经常来,找到好地方了,呵呵!多谢斑竹!
2005-01-24 17:23
jianfeixu
Rank: 1
等 级:新手上路
帖 子:96
专家分:0
注 册:2005-1-24
得分:0 
关他什么鸟!只要可以解决问题的就是好鸟!鸟哥!
2005-01-24 20:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-11659-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.170827 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved