Hi omoz4real.
In your code,i found that you hadn't opened your connection before executed a command,so you probably couldn't connect to the database.
If you didn't intend to execute a command which return a table as a result,you should use another way.There is xxCommand.ExecuteNonQuery().
I have a small attached program that clear your confuse.
Hope this useful.
You're program is doing EXACTLY what I need mine to do, but looking through your code I tried to change mine around so to work w/ my DB, and it's failing at the ExecuteNonQuery line.
string userName;
string passWord;
string verify;
string streetAddress;
string address2;
string City;
string State;
int Zip;
string phoneNumber;
string fName;
string lName;
userName = txtUserName.Text;
streetAddress = txtStreetAddress.Text;
address2 = txtAddress2.Text;
City = txtCity.Text;
State = txtState.Text;
try
{
Zip = Int32.Parse(txtZip.Text);
}
catch
{
MessageBox.Show("Zip Code must be a number", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
phoneNumber = txtPhoneNumber.Text;
passWord = mtxtpassword.Text;
verify = mtxtVerify.Text;
fName = txtFirstName.Text;
lName = txtLastName.Text;
if (MAconn != null && MAconn.State == ConnectionState.Open)
{
MAconn.Close();
MAcmd.Dispose();
}
try
{
MAconn = new OleDbConnection();
MAconn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Geodude\\Documents\\Database1.mdb";
MAconn.Open();
MAcmd = MAconn.CreateCommand();
}
catch
{
MessageBox.Show("Database unable to be opened.");
return;
}
MAcmd.CommandText = "INSERT INTO table1 VALUES('"+userName+"',"+ passWord+"',"+
fName+"',"+ lName+"',"+ streetAddress+"',"+ address2+"',"+ City+"',"+ State+"',"+ Zip+"',"+ phoneNumber+"')";
try
{
int row_affected = MAcmd.ExecuteNonQuery();
MessageBox.Show(row_affected.ToString() + " row affected.", "Insert command result");
}
catch
{
MessageBox.Show("Error");
}
this is my code, it is being used for a "Register" form, on a program I have to write to create a Ticketmaster esque program, and like I said you're program is doing EXACTLY what i've been searching the internet for like 4hrs and came up empty handed. If you could possibly tell me where I'm messing up I would really appreciate it.