here is my code for updation date time in database. I am wondering that it is working in my machine but not in my friends machine. see the code below
this is my sp
ALTER procedure [dbo].[Update_Timing]
(
@User_Id nvarchar (50)=NULL,
@Login_Date datetime=NULL,
@In_Time datetime=NULL,
@Out_Time datetime=NULL
)
AS
SET DATEFORMAT DMY --accept date in dd-MM-yyyy format
DECLARE @ParameterDate DATETIME
DECLARE @DateCheck VARCHAR(20)=CONVERT(VARCHAR,@Login_Date,101)
SET @ParameterDate=@DateCheck
SET DATEFORMAT MDY -- reset date format
update mtblAttendance set In_Time=@In_Time, Out_Time=@Out_Time
where User_Id=@User_Id
and CONVERT(VARCHAR,Login_Date,103)=CONVERT(VARCHAR,@DateCheck,103)
and here is my code for cs file
protected void Button1_Click(object sender, EventArgs e)
{
Business_Logic bal = new Business_Logic();
string in_time = TimeSelector1.Hour.ToString() + ":" + TimeSelector1.Minute.ToString() + " " + TimeSelector1.AmPm.ToString();
string out_time= TimeSelector2.Hour.ToString() + ":" + TimeSelector2.Minute.ToString() + " " + TimeSelector2.AmPm.ToString();
try
{
int update_timing = bal.Update_Timing(Convert.ToDateTime(in_time), Convert.ToDateTime(out_time), lblUser_Id.Text, Convert.ToDateTime(lblLogin_Date.Text));
ddlEmployee.SelectedIndex = ddlEmployee.Items.IndexOf(ddlEmployee.Items.FindByText("--Select--"));
WebMsgBox.Show("Updated");
Panel1.Visible = false;
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}
in my machine is shows msgs Updated In my friend's machine it caught an exception that "String was not recognized as a
valid DateTime".
how it can be possible ?
It is our choices that show what we truly are, far more than our abilities...
Why are you converting your DateTimes to varchar at all? Is it to get rid of the time component? There are better ways of doing it. But frankly, here is how I would write your proc:
ALTER procedure [dbo].[Update_Timing]
(
@User_Id nvarchar (50)=NULL,
@Login_Date datetime=NULL,
@In_Time datetime=NULL,
@Out_Time datetime=NULL
)
AS
update mtblAttendance set In_Time=@In_Time, Out_Time=@Out_Time
where User_Id=@User_Id
and DATEDIFF(dd,Login_Date,@Login_Date)=0
ALTER procedure [dbo].[Update_Timing]
(
@User_Id nvarchar (50)=NULL,
@Login_Date datetime=NULL,
@In_Time datetime=NULL,
@Out_Time datetime=NULL
)
AS
update mtblAttendance set In_Time=@In_Time, Out_Time=@Out_Time
where User_Id=@User_Id
and DATEDIFF(dd,Login_Date,@Login_Date)=0
shows the same exception(this time in my machine)
It is our choices that show what we truly are, far more than our abilities...
You could try to modify your code like this in your code, "int update_timing = bal.Update_Timing(lblUser_Id.Text, Convert.ToDateTime(lblLogin_Date.Text), Convert.ToDateTime(in_time), Convert.ToDateTime(out_time)); "
stored procedure.
ALTER procedure [dbo].[Update_Timing]
(
@User_Id nvarchar (50)=NULL,
@Login_Date datetime=NULL,
@In_Time datetime=NULL,
@Out_Time datetime=NULL
)
AS
--make sure your data format is correct.
select @User_Id,@Login_Date,@In_Time,@Out_Time
update mtblAttendance
set In_Time=@In_Time, Out_Time=@Out_Time
where User_Id=@User_Id
and CONVERT(VARCHAR,Login_Date,103)=CONVERT(VARCHAR,@Login_Date,103)
Best Regards,
Please mark the replies as answers if they help or unmark if not.
Feedback to us
You could try to modify your code like this in your code, "int update_timing = bal.Update_Timing(lblUser_Id.Text, Convert.ToDateTime(lblLogin_Date.Text), Convert.ToDateTime(in_time), Convert.ToDateTime(out_time)); "
stored procedure.
ALTER procedure [dbo].[Update_Timing]
(
@User_Id nvarchar (50)=NULL,
@Login_Date datetime=NULL,
@In_Time datetime=NULL,
@Out_Time datetime=NULL
)
AS
--make sure your data format is correct.
select @User_Id,@Login_Date,@In_Time,@Out_Time
update mtblAttendance
set In_Time=@In_Time, Out_Time=@Out_Time
where User_Id=@User_Id
and CONVERT(VARCHAR,Login_Date,103)=CONVERT(VARCHAR,@Login_Date,103)
thanks
Chen Yu - MSFT, although your code executed perfectly but it is starnge that there is no updation in database. how it can be possible.
It is our choices that show what we truly are, far more than our abilities...
demoninside9
Participant
1238 Points
1720 Posts
same code working fine in one machine but not in another
Dec 20, 2012 04:30 AM|LINK
hi all,
here is my code for updation date time in database. I am wondering that it is working in my machine but not in my friends machine. see the code below
this is my sp ALTER procedure [dbo].[Update_Timing] ( @User_Id nvarchar (50)=NULL, @Login_Date datetime=NULL, @In_Time datetime=NULL, @Out_Time datetime=NULL ) AS SET DATEFORMAT DMY --accept date in dd-MM-yyyy format DECLARE @ParameterDate DATETIME DECLARE @DateCheck VARCHAR(20)=CONVERT(VARCHAR,@Login_Date,101) SET @ParameterDate=@DateCheck SET DATEFORMAT MDY -- reset date format update mtblAttendance set In_Time=@In_Time, Out_Time=@Out_Time where User_Id=@User_Id and CONVERT(VARCHAR,Login_Date,103)=CONVERT(VARCHAR,@DateCheck,103) and here is my code for cs file protected void Button1_Click(object sender, EventArgs e) { Business_Logic bal = new Business_Logic(); string in_time = TimeSelector1.Hour.ToString() + ":" + TimeSelector1.Minute.ToString() + " " + TimeSelector1.AmPm.ToString(); string out_time= TimeSelector2.Hour.ToString() + ":" + TimeSelector2.Minute.ToString() + " " + TimeSelector2.AmPm.ToString(); try { int update_timing = bal.Update_Timing(Convert.ToDateTime(in_time), Convert.ToDateTime(out_time), lblUser_Id.Text, Convert.ToDateTime(lblLogin_Date.Text)); ddlEmployee.SelectedIndex = ddlEmployee.Items.IndexOf(ddlEmployee.Items.FindByText("--Select--")); WebMsgBox.Show("Updated"); Panel1.Visible = false; } catch (Exception ex) { WebMsgBox.Show(ex.Message); } }in my machine is shows msgs Updated In my friend's machine it caught an exception that "String was not recognized as a valid DateTime".
how it can be possible ?
Rajneesh Ver...
All-Star
37226 Points
6820 Posts
Re: same code working fine in one machine but not in another
Dec 20, 2012 04:54 AM|LINK
Check the Time Zone and Date format in your machine and your friends machine.
www.rajneeshverma.com
Keep Forums Clean || Use Alert Moderators.
demoninside9
Participant
1238 Points
1720 Posts
Re: same code working fine in one machine but not in another
Dec 20, 2012 05:00 AM|LINK
they both are same. see the imahe below
TabAlleman
All-Star
15571 Points
2700 Posts
Re: same code working fine in one machine but not in another
Dec 20, 2012 01:23 PM|LINK
Why are you converting your DateTimes to varchar at all? Is it to get rid of the time component? There are better ways of doing it. But frankly, here is how I would write your proc:
ALTER procedure [dbo].[Update_Timing] ( @User_Id nvarchar (50)=NULL, @Login_Date datetime=NULL, @In_Time datetime=NULL, @Out_Time datetime=NULL ) AS update mtblAttendance set In_Time=@In_Time, Out_Time=@Out_Time where User_Id=@User_Id and DATEDIFF(dd,Login_Date,@Login_Date)=0luckyforu200...
Participant
1207 Points
450 Posts
Re: same code working fine in one machine but not in another
Dec 20, 2012 02:16 PM|LINK
pass data time in the following format to stored procedure
(eg dd MMM yyyy hh:mm:ss i.e. 12 Jan 2012 13:00:00)
demoninside9
Participant
1238 Points
1720 Posts
Re: same code working fine in one machine but not in another
Dec 21, 2012 04:11 AM|LINK
shows the same exception(this time in my machine)
Chen Yu - MS...
All-Star
21598 Points
2493 Posts
Microsoft
Re: same code working fine in one machine but not in another
Dec 21, 2012 08:24 AM|LINK
Hi,
You could try to modify your code like this in your code, "int update_timing = bal.Update_Timing(lblUser_Id.Text, Convert.ToDateTime(lblLogin_Date.Text), Convert.ToDateTime(in_time), Convert.ToDateTime(out_time)); "
stored procedure.
ALTER procedure [dbo].[Update_Timing] ( @User_Id nvarchar (50)=NULL, @Login_Date datetime=NULL, @In_Time datetime=NULL, @Out_Time datetime=NULL ) AS --make sure your data format is correct. select @User_Id,@Login_Date,@In_Time,@Out_Time update mtblAttendance set In_Time=@In_Time, Out_Time=@Out_Time where User_Id=@User_Id and CONVERT(VARCHAR,Login_Date,103)=CONVERT(VARCHAR,@Login_Date,103)Best Regards,
Feedback to us
Develop and promote your apps in Windows Store
prabu.raveen...
Contributor
5022 Points
956 Posts
Re: same code working fine in one machine but not in another
Dec 21, 2012 08:35 AM|LINK
Hi,
It was clear that you friend's machine was set to MM/dd/yyyy format, please look at in the bottom right corner.
To change the date format refer the below link,
http://www.sevenforums.com/tutorials/3529-date-format-change.html
you should set short date format to dd/MM/yyyy
and then try.
Regards,
Prabu R
webaspdotnet
Member
52 Points
38 Posts
Re: same code working fine in one machine but not in another
Dec 21, 2012 08:56 AM|LINK
Have you check where your code throwing error ?
i.e exception comming from SP or coding.
check in_time and out_time values in both machine.
check your server machien i.e sql machine time zone and asp.net running machine time zone.
Software Engineer
IGate Global Solution.
My Technical Blog :: Ask Me Question.
demoninside9
Participant
1238 Points
1720 Posts
Re: same code working fine in one machine but not in another
Dec 21, 2012 09:47 AM|LINK
thanks Chen Yu - MSFT, although your code executed perfectly but it is starnge that there is no updation in database. how it can be possible.