我正在使用C#.NET和SQL Server 2008的桌面应用程序.......我在其中采取了一个标签名称日期,并有一个工具箱日期时间选择器并且还在数据库中使用了字段名称日期........... nw我想使用datetimepicker插入日期throgh表单并获取插入数据库.......插入日期使用c#.Net到SQL Server 2008使用插入查询
使用代码
SqlConnection con = new SqlConnection("Data Source=SW-PC-20;Integrated security =SSPI;Initial catalog=PSM");
con.Open();
SqlCommand cmd = new SqlCommand("insert into Campaign(Campaign_id,List_of_thresholds,Duration,Starting_Date,Ending_Date,Total_Budget_of_all_thresholds) values (" + Convert.ToInt32(cbocampaign.Text) + ",'" + cbolist_threshold.Text + "',' " + txtduration.Text + " '," + Convert.ToDateTime(DateTimePicker1.Text) + "," + Convert.ToDateTime(DateTimePicker2.Text) + "," + Convert.ToInt32(txtbudget.Text) + ")", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Insertion successfully done");
* 问题: *它不能转换日期时间选择器错误发生的历史.....
Convert.ToDateTime(DateTimePicker1.Text) `
请给我这个解决方案,也给我使用数据网格视图
问候
shivani
你会给我们这个错误吗? – 2011-04-28 09:26:10
“一步到位的人们,是时候玩猜猜错误了!” – 2011-04-28 09:27:17
哦,如果只有DateTimePicker控件将选定的值作为DateTime公开,而不是强迫你将datetime作为文本值操纵。哦。 http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.value.aspx – 2011-04-28 09:40:40