我在我的dbconnect類中有這個主要的插入函數。我想使用所有的形式這個功能。和我打電話功能,但它不工作。我能做什麼 ?我的錯誤在哪裏?數組參數插入函數dbconnect與arraylist
這是我的數據庫連接類
public bool OpenConnection()
{
try
{
connection.Open();
return true;
}
catch (MySqlException ex)
{
//When handling errors, you can your application's response based
//on the error number.
//The two most common error numbers when connecting are as follows:
//0: Cannot connect to server.
//1045: Invalid user name and/or password.
switch (ex.Number)
{
case 0:
MessageBox.Show("Cannot connect to server. Contact administrator");
break;
case 1045:
MessageBox.Show("Invalid username/password, please try again");
break;
}
return false;
}
}
//Close connection
public bool CloseConnection()
{
try
{
connection.Close();
return true;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
//Insert statement
public void Insert(string tablename , ArrayList [] values)
{
string val = "VALUES" + "(" ;
for (int i=0; i<values.Length; i++ )
{
if (values.Length > 1)
val += values[i] + ",";
else val += values[i];
}
val += ")";
string query = "INSERT INTO "+ tablename + val ;
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
//Execute command
cmd.ExecuteNonQuery();
//close connection
this.CloseConnection();
}
}
這裏是調用函數按鈕點擊時。我想,所以我沒有找到什麼來這裏「????」
private void button1_Click(object sender, EventArgs e)
{
DBConnect conn = new DBConnect();
conn.Insert("rezervationinformations", *????*);
}
一個數組你想要插入的值。 – McNets
您還需要更改'「VALUES」+「(」;'''VALUES「+」(「;',以便它們是您的表名和關鍵字VALUES之間的空格 – jaredbaszler
我知道我有一個語法錯誤,但我需要按鈕上的函數參數點擊 –