我可以在代码中创建具有唯一名称的表,但是当我想使用文本框的内容创建具有动态名称的表时,它会在消息框中显示“CREATE TABLE 语句中的语法错误”。我的代码:
private void createTableInDatabase(string fName, string lName)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Project\Learning\Visual C#\Form\Tailor Assistance\Tailor Assistance\bin\Release\Tailor Assistance.mdb";
conn.Open();
string tableName = fName + " " + lName;
OleDbCommand cmmd = new OleDbCommand("", conn);
cmmd.CommandText = "CREATE TABLE " + tableName + "( [ID] Counter Primary Key, [FirstName] Text, [LastName] Text, [Gender] Text, [Phone] Text, [CellPhone] Text, [FriendsFirstName] Text, [FriendsLastName] Text, [RegisterDate] Text, [Size] Text, [Description] Text)";
if (conn.State == ConnectionState.Open)
{
try
{
cmmd.ExecuteNonQuery();
MessageBox.Show("Add!");
conn.Close();
}
catch (OleDbException expe)
{
MessageBox.Show(expe.Message);
conn.Close();
}
}
else
{
MessageBox.Show("Error!");
}
}
有什么问题?