ok, so here's the deal. i'm a bit confused about .sdf and .mdf files, i know i should post this in databases, but the topic is also relevant here so i'll just get right to it.
1. I'm working on an inventory project which will be a standalone, so i decided to add a dbase to it (.sdf, naive me) and i want to connect to it and write to the dbase via code behind but i don't know how. a friend looked at it and ridiculed me for using the .sdf. he said i should have used .mdf and he gave me this code to work with:
#region PRIVATE OBJECTS
//sql command objets
private SqlCommand myCommand;
//sql connection obj
private SqlConnection myConnection;
//sql adapter obj
private SqlDataAdapter myAdapter;
#endregion
public Add_Client_Employee()
{
InitializeComponent();
}
private void SaveBtn_Click(object sender, EventArgs e)
{
if (ClientRBtn.Checked)
{
if (!Name_Tb.Equals("") && !Location_Tb.Equals("") && !Contact_Tb.Equals(""))
{
//insert client info into dbase
//notice -- create a class for connection open and close
myConnection = new SqlConnection(@"Data Source=C:\Users\Soft-tribe\My Docs\Bakery_Inventory\Bakery_Inventory\Bake.sdf");
myConnection.Open();
myCommand = new SqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = "insert into table_client values('" +
Name_Tb.Text + "','" + Location_Tb.Text + "','" +
Contact_Tb.Text + "')";
//myConnection.Open();
if (myCommand.ExecuteNonQuery() > 0)
{
MessageBox.Show("insert successful");
}
myConnection.Close();
}
}
which i changed to
#region PRIVATE OBJECTS
//sql command objets
private IDbCommand myCommand;
//sql connection obj
private IDbConnection myConnection;
//sql adapter obj
private IDbDataAdapter myAdapter;
#endregion
the program runs to the point where it has to open the dbase and it gives me a 'database not found' error.
2. i tried to add an .mdf file to it so i could redo the dbase again, but it gave me a 'generating user instance is disabled'.
3. Another friend said why don't i just build the dbase in sql and connect to it. which means the client must have an sql server to connect the program to. but that is not what i had in mind
so please people advice me on what to do and how to solve this issue, cos this life is killing me.