How to insert date/time into access database
-
viernes, 03 de agosto de 2012 18:40
I would like insert user defined dates and times into a access database... After doing some research, this is my first try.
Here is my code:
rotected void Button1_Click(object sender, EventArgs e) { DateTime startdate = DateTime.Parse(TextBox2.Text); DateTime enddate = DateTime.Parse(TextBox3.Text); using (OleDbConnection conn = new OleDbConnection()) { conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\AIRSIGNDMC\AirSign Server\AirSignProgramming\AirSignDatabase.accdb"; string sql = string.Format("INSERT INTO Events(EventName, StartDate&Time, EndDate&Time, Location, Notes, Clients) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", TextBox1.Text, startdate, enddate, TextBox4.Text, TextBox5.Text, TextBox6.Text); using (OleDbCommand cmd = new OleDbCommand(sql, conn)) { try { conn.Open(); cmd.ExecuteNonQuery(); } finally { conn.Close(); } conn.Close(); { GridView1.DataSource = null; GridView1.DataBind(); } } } } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void AccessDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e) { } }thanks for all your help guys, I know I ask for help a lot on here...
- Editado l3elivE viernes, 03 de agosto de 2012 18:41
Todas las respuestas
-
viernes, 03 de agosto de 2012 18:42
oh, and this is the error I am getting:
No value given for one or more required parameters.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. -
viernes, 03 de agosto de 2012 19:06
Youre missing a parameter
"INSERT INTO Events(EventName, StartDate&Time, EndDate&Time, Location, Notes, Clients) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}')", TextBox1.Text, startdate, enddate, TextBox4.Text, TextBox5.Text, TextBox6.Text)
EventName = 0, StartDate&Time,=1 EndDate&Time=2, Location=3, Notes=4, Clients=56 ?
:)
//SFP
- Marcado como respuesta l3elivE viernes, 03 de agosto de 2012 19:20
-
viernes, 03 de agosto de 2012 19:21
myDataGrid.Columns[0].HeaderText = "My Header"
For further information please look at this
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.name.aspx
//SFP

