Correct connection string from C# Windows Form App into Ms SQL Server
I'm not able to insert my data from C# Windows Forms Application with the code below, the error message is below as well, please note that my MS SQL Server database name is called CaPremier
System.ArgumentException: 'Keyword not supported: 'initialcatalog ( This is my error message I'm getting)
using System;
using System.Collections.Generic ;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnInsert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=SQL EXPRESS;InitialCatalog=CaP remier.mdf ;Integrate d Security=True;User Instance=True");
SqlCommand cmd;
con.Open();
string s = "insert into SalesTraining values(@customer,@address) ";
cmd = new SqlCommand(s, con);
cmd.Parameters.AddWithValu e("@custom er", txtCustomer.Text);
cmd.Parameters.AddWithValu e("@addres s", txtAddress.Text);
cmd.CommandType = CommandType.Text;
int i = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(i + " Row(s) Inserted ");
}
}
}
Kindly see how you can help
Regards
Chris
System.ArgumentException: 'Keyword not supported: 'initialcatalog ( This is my error message I'm getting)
using System;
using System.Collections.Generic
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnInsert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=SQL EXPRESS;InitialCatalog=CaP
SqlCommand cmd;
con.Open();
string s = "insert into SalesTraining values(@customer,@address)
cmd = new SqlCommand(s, con);
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.CommandType = CommandType.Text;
int i = cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show(i + " Row(s) Inserted ");
}
}
}
Kindly see how you can help
Regards
Chris
"Initial Catalog" needs to be two words separated by a space.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.