Click here to Skip to main content
15,919,245 members
Home / Discussions / C#
   

C#

 
QuestionWorking with "Date/Time" field of "Access Database" in C# Pin
Sourie23-Sep-08 10:06
Sourie23-Sep-08 10:06 
AnswerRe: Working with "Date/Time" field of "Access Database" in C# Pin
Ennis Ray Lynch, Jr.23-Sep-08 10:28
Ennis Ray Lynch, Jr.23-Sep-08 10:28 
AnswerRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius23-Sep-08 10:47
mentorWendelius23-Sep-08 10:47 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie23-Sep-08 17:54
Sourie23-Sep-08 17:54 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius23-Sep-08 18:18
mentorWendelius23-Sep-08 18:18 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie23-Sep-08 18:31
Sourie23-Sep-08 18:31 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius23-Sep-08 18:48
mentorWendelius23-Sep-08 18:48 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie24-Sep-08 0:46
Sourie24-Sep-08 0:46 
This is my code:
I reach an error: Syntax error in INSERT INTO statement.
I know this error is because of line : dr["Date"] = Convert.ToDateTime(DateTime.Now.ToShortDateString());
But I donno how to solve it. I have a field named "Date", with datatype "DateTime", and with format "ShortDate".

OleDbDataAdapter adp = new OleDbDataAdapter();
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source=f:\Wire1\WireDb.mdb");
conn.Close();

OleDbCommand cmd = new OleDbCommand("SELECT * FROM tbl1 ORDER BY Code", conn);
adp.SelectCommand = cmd;
OleDbCommandBuilder cb = new OleDbCommandBuilder(adp);
DataSet ds = new DataSet("tbl1");
DataTable dt = new DataTable();
conn.Open();
adp.Fill(ds, "tbl1");
dt = ds.Tables[0];
DataRow dr = ds.Tables[0].NewRow();
int x = dt.Rows.Count;
dr["Code"] = ++x;
dr["Street"] = "Molavi";
dr["Alley"] = "Molavi 34";
dr["Status"] = true;
dr["Date"] = Convert.ToDateTime(DateTime.Now.ToShortDateString());

ds.Tables[0].Rows.Add(dr);
adp.Update(dt);
ds.Clear();
adp.Fill(ds.Tables[0]);
conn.Close();

Sourie

GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius24-Sep-08 7:49
mentorWendelius24-Sep-08 7:49 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie24-Sep-08 9:01
Sourie24-Sep-08 9:01 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius24-Sep-08 9:04
mentorWendelius24-Sep-08 9:04 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie24-Sep-08 10:06
Sourie24-Sep-08 10:06 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius24-Sep-08 10:48
mentorWendelius24-Sep-08 10:48 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie24-Sep-08 18:25
Sourie24-Sep-08 18:25 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Wendelius24-Sep-08 18:36
mentorWendelius24-Sep-08 18:36 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
Sourie24-Sep-08 20:13
Sourie24-Sep-08 20:13 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
meenana24-Oct-10 2:22
meenana24-Oct-10 2:22 
GeneralRe: Working with "Date/Time" field of "Access Database" in C# Pin
RaviRanjanKr24-Oct-10 9:24
professionalRaviRanjanKr24-Oct-10 9:24 
QuestionDesign a Page and Print it ... Pin
I Believe In GOD23-Sep-08 6:24
I Believe In GOD23-Sep-08 6:24 
AnswerRe: Design a Page and Print it ... Pin
Wendelius23-Sep-08 8:21
mentorWendelius23-Sep-08 8:21 
QuestionTaborder for Dynamically-Created Controls Pin
danielhasdibs23-Sep-08 5:29
danielhasdibs23-Sep-08 5:29 
AnswerRe: Taborder for Dynamically-Created Controls Pin
J4amieC23-Sep-08 6:03
J4amieC23-Sep-08 6:03 
GeneralRe: Taborder for Dynamically-Created Controls Pin
danielhasdibs23-Sep-08 6:05
danielhasdibs23-Sep-08 6:05 
AnswerRe: Taborder for Dynamically-Created Controls Pin
teejayem23-Sep-08 6:20
teejayem23-Sep-08 6:20 
GeneralRe: Taborder for Dynamically-Created Controls Pin
danielhasdibs23-Sep-08 6:25
danielhasdibs23-Sep-08 6:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.