I'm trying to insert user name and password into an access database through a create button. However, anytime I click on the create button there is an exception which suggests that there is a problem with my sql insert statements. I need help to ascertain what the problem is and how I can rectify that problem.
private void btnCreate_Click(object sender, System.EventArgs e){ OleDbConnection sgConn = null; string sgConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;"+"Data Source= C:\\Documents and Settings\\flexcube\\My Documents\\Visual Studio Projects\\sgssbproject\\sgDataBase.mdb"; if(txtUserName.Text==""){ MessageBox.Show("Please Check Empty Field"); } else{ try{ string name,password;name = txtUserName.Text; password = txtPassword.Text; string commandString ="Insert into Users (username,password)values(name,password)";sgConn = new OleDbConnection(sgConnStr);OleDbCommand myUsersCommand = new OleDbCommand(commandString,sgConn);sgConn.Open(); myUsersCommand.ExecuteNonQuery(); txtUserName.Text =""; txtPassword.Text = ""; } catch(Exception exc){ MessageBox.Show(exc.ToString()); } finally{ sgConn.Close(); } } |
Thank you very much.
Regards,
Derry

OleDBCommand: what might be the problem?
dwith
Thank you.
Derry
FinallyInSeattle
string commandString ="Insert into Users (username,password)values('" + name + "','" + password + "')";
Goye
string commandString ="Insert into Users (username,[password])values('" + name + "','" + password + "')";
ahr
What I really want to do is this:
I have a form that create accounts for users of an application. To create the account, you have to enter your username and password in the textboxes on the user.cs form. When the create button is clicked, the username and the password in the textboxes should be written in the users table of the project database. The users table has username and password as fields, with all of them having types text. This led me to declare new strings name and passord and let their values equal txtUserName.Text and txtPassword.Text. I then use those strings to as my values in the insert statement. Hope u get my drift now.
Thank you for your response anyway.
Regards,
Derry
MMMSobo