我的sql代码
CREATE PROC [ADD_VACATION] @vacationStart date,@vacationEnd date,@vacationMem nvarchar (100) = NulL,@IDVacationKind_L int,@IDMember_L intAS INSERT INTO [tblVacation] ([vacationStart],[vacationEnd],[vacationMem],[IDVacationKind_L],[IDMember_L]) VALUES (@vacationStart,@vacationEnd,@vacationMem,@IDVacationKind_L,@IDMember_L)
C#代码:
public voID ADD_VACATION(string vacationStart,string vacationEnd,string vacationMem,int IDVacationKind_L,int IDMember_L){ DAL.open(); sqlParameter[] param = new sqlParameter[5]; param[0] = new sqlParameter("@vacationStart",sqlDbType.Date); param[0].Value = vacationStart; param[1] = new sqlParameter("@vacationEnd",sqlDbType.Date); param[1].Value = vacationEnd; param[2] = new sqlParameter("@vacationMem ",sqlDbType.NVarChar,100); param[2].Value = vacationMem; param[3] = new sqlParameter("@IDVacationKind_L",sqlDbType.Int); param[3].Value = IDVacationKind_L; param[4] = new sqlParameter("@IDMember_L",sqlDbType.Int); param[4].Value = IDMember_L; DAL.ExecuteCommand("ADD_VACATION",param); DAL.close();}
而事件
private voID btnAddVacation_Click(object sender,EventArgs e){ CMS.ADD_VACATION( dtp_VacationStart.Text,dtp_VacationEnd.Text,txtVacationMemory.Text,Convert.ToInt32(cmbVacationKind.SelectedValue),Convert.ToInt32(dgMember_Grade.CurrentRow.Cells[0].Value.ToString())); MessageBox.Show("Added Successfuly"," ",MessageBoxbuttons.OK,MessageBoxIcon.information);}
此代码给出了一个错误:输入字符串格式不正确.
谢谢大家…抱歉令人困惑..这是我的第一个问题
解决方法 您的sqlParameter @vacationStart的类型为DateTime,但您为其指定了一个字符串.您应该获取DateTimePicker的DateTime值(而不是DateTimePicker.Text中的字符串表示):
DateTime vacationStart = dtp_VacationStart.Value;
并更改ADD_VACATION的签名:
public voID ADD_VACATION(DateTime vacationStart,...
现在你可以使用它:
private voID btnAddVacation_Click(object sender,EventArgs e){ DateTime vacationStart = dtp_VacationStart.Value; CMS.ADD_VACATION(vacationStart,...总结
以上是内存溢出为你收集整理的c# – 将DateTimePicker值传递给存储过程全部内容,希望文章能够帮你解决c# – 将DateTimePicker值传递给存储过程所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)