Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
{OleDbConnection mycon = new OleDbConnection();

        OleDbCommand command = new OleDbCommand();
        command.CommandText = "INSERT INTO Table1 (Emp_ID, Asset_ID, Actual_Start) VALUES (?, ?, ?)";

        command.Parameters.Add("@Emp_ID", OleDbType.VarChar, 80).Value = textBox1.Text;
        command.Parameters.Add("@Asset_ID", OleDbType.VarChar, 80).Value = textBox2.Text;
        command.Parameters.Add("@Actual_Start", OleDbType.Date).Value = DateTime.Now;

        command.Connection = mycon;
        mycon.Open();
        command.ExecuteNonQuery();
}


This is the code I have written. I got the error "ConnectionString property has not been initialized."
Posted
Updated 22-Jan-14 19:11pm
v2

change your code to this
C#
command.CommandText = "INSERT INTO Table1 (Emp_ID, Asset_ID, Actual_Start) VALUES (@Emp_ID, @Asset_ID, @Actual_Start)";


but your error is regarding the connection string.
check this

OLEDB Connection strings/[^]
http://www.connectionstrings.com/access/[^]
 
Share this answer
 
Comments
Member 10538358 23-Jan-14 1:53am    
@KARTHIK, well this is embarassing but I had acccidentally deleted the conection string and it drew my attention pretty late. Thanks anyways.
Karthik_Mahalingam 23-Jan-14 2:05am    
Its ok , it happens sometimes :)
welcome :)
private void button1_Click(object sender, EventArgs e)
{OleDbConnection mycon = new OleDbConnection();
mycon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Dinesh\C#\GIS_Power\WindowsFormsApplication1\bin\Power_DB1.accdb";

OleDbCommand command = new OleDbCommand();
command.CommandText = "INSERT INTO Table1 (Emp_ID, Asset_ID, Actual_Start) VALUES (?, ?, ?)";

command.Parameters.Add("@Emp_ID", OleDbType.VarChar, 80).Value = textBox1.Text;
command.Parameters.Add("@Asset_ID", OleDbType.VarChar, 80).Value = textBox2.Text;
command.Parameters.Add("@Actual_Start", OleDbType.Date).Value = DateTime.Now;

mycon.Open();
command.Connection = mycon;
command.ExecuteNonQuery();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900