一個或多個必需參數給定值,沒有任何一個或多個必需的參數給出了mycommand.ExecuteNonQuery()... 值我不知道是什麼問題... 五月任何人的幫助? THX =)沒有與C#
System.Data.OleDb.OleDbConnection cnregister;
System.Data.OleDb.OleDbCommand cnUpreg;
System.Data.OleDb.OleDbDataReader ReaderReg;
private void cmdregister_Click(object sender, EventArgs e)
{
cnregister = new System.Data.OleDb.OleDbConnection();
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; Data Source=|DataDirectory|Register.mdb";
OleDbConnection myConnection = new OleDbConnection(connectionString);
string InputId_reg;
string InputPass_reg;
InputId_reg = txtuserid_reg.Text;
InputPass_reg = txtpass_reg.Text;
myConnection.Open();
OleDbCommand cnUpreg = new OleDbCommand("SELECT * FROM tblRegister", myConnection);
ReaderReg = cnUpreg.ExecuteReader(); //reader open
while (ReaderReg.Read())
{
if (InputId_reg == (ReaderReg["UserID"].ToString()))
{ //to check whether the UserID is same with the ID in the database
// if yes, a message box will promt
MessageBox.Show("The user had register");
txtuserid_reg.Focus();
txtuserid_reg.Clear();
ReaderReg.Close();
myConnection.Close();
break;
}
else
{
string query123 = "INSERT INTO [tblRegister] ([UserID], [Password], [UserName], [UserJob]) VALUES(add1, add2, add3, add4)";
OleDbCommand mycommand = new OleDbCommand(query123, myConnection);
mycommand.Parameters.AddWithValue("add1", txtuserid_reg.Text);
mycommand.Parameters.AddWithValue("add2", txtpass_reg.Text);
mycommand.ExecuteNonQuery();
ReaderReg.Close();
myConnection.Close();
MessageBox.Show("Data save successfully!");
break;
}
}
MessageBox.Show("Break succesffully");
}
}
OPS之前......解決問題..因爲我必須先嚐試2而不是全部4 ...非常感謝你=) – Cwz90
@ Cwz90:沒問題。有時它只需要第二組眼睛。 –