I am really new to programming, so excuse me if my knowledge seems really inadequate. I am involved in a C # project for my school, and I am having problems running my database.
Here are some codes:
private void buttonPurchase_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Purchase?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection("CarDBConnectionString");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT into invoiceTbl(invoiceId, date, time) values (1, 21/6/2014, 11:13PM)";
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
}
I encountered an error with these codes
The format of the initialization string does not comply with the specification starting with index 0 1, in the section "Unhandled exception of type" System.ArgumentException "occurred in System.Data.dll"
Also given are the codes from my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="CarDBConnectionString" connectionString="Data Source=(LocalDB)\v11.0;InitialCatalogue=CarDB;AttachDbFilename=|DataDirectory|\CarDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="Draft_1.Properties.Settings.CarDBConnectionString"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\CarDB.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
I tried searching all over the world, but I can not understand any of the solutions :-( Any help would be greatly appreciated, thanks!