TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ullas K
NA
55
0
Datetime from datagridview insertion error
Aug 9 2012 8:33 AM
I have a datagridview with columns,Book no,Book Name,Issue Date,Return Date,remarks.
i have set the issuedate and returndate
format
as
"d"
(ie,dd/MM/yyyy) and
issue date
cell value as
datetime.now
.
when i am inserting the values it is giving a conversion error.My
sqlserver
issuedate
and
returndate
columns are of
datetime
datatypes
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.
when i try to insert issuedate as follows it is working
issuedt= DateTime.Now.ToString("MM/dd/yyyy");
but when i am trying to fetch the value from datagridview cell for insert it is giving the above error
my code is
;
{
DataGridViewRow dgr;
LibraryLib.Library obj = new LibraryLib.Library();
int i;
string bookno, remarks ;
DateTime issuedt, returndt;
for (i = 0; i < (dataGridView1.Rows.Count - 1); i++)
{
dgr = dataGridView1.Rows[i];
bookno = dgr.Cells[1].Value.ToString();
issuedt = DateTime.Parse(dgr.Cells[3].Value.ToString());
//issuedt= DateTime.Now.ToString("MM/dd/yyyy"); this is working
returndt = DateTime.Parse(dgr.Cells[4].Value.ToString());
remarks = dgr.Cells[5].Value.ToString();
obj.idu("insert into bookissue values(" + t1.Text.ToString() + ",'" + bookno + "','" + issuedt + "','" + returndt + "','" + remarks + "')");
}
pls help me get out of this situation as i am new to c#.net
thanks in advance
Reply
Answers (
2
)
Data mining
Print group of selected Word Doc file saved in folder