我有一个MS ACCESS 2003数据库,其中有一个表“TABLEA”。
然后我使用OLEDB连接并创建一个表,然后以编程方式填充数据:
string create_table_script = @" CREATE TABLE [" + Path.GetFileNameWithoutExtension(filename) + @"](
[AutoID] COUNTER PRIMARY KEY ,
[CAS] text(255) ,
[Listed French Ingredient No] text(255) ,
[Name] text(255) ,
[GC] text(20) ,
[Grp_Code] text(10) ,
[Galsyn] Memo ,
[Notes LCN] text(255) ,
[Notes LFIN] text(255) ,
[%w/w] text(255) )";
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + fullpath + ";" + " User Id=admin; Password=";
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand SelectCommand = new OleDbCommand(create_table_script, connection);
connection.Open();
try
{
SelectCommand.ExecuteNonQuery();
}
catch (OleDbException ex)
{
Console.WriteLine(ex.Message);
}
finally
{
connection.Close();
}
}
填写此表后,
每当我打开此访问数据库
时,我只收到此消息一次“31613您已选择”表和相关视图“作为在数据库中对对象进行分组的方法。访问需要更新有关对象依赖关系的信息以创建组。这将需要一些时间来处理大型数据库。您想要继续?“
我不知道我哪里错了。我为此瞪眼但没有任何好处。 我认为创建表格中存在一些问题
感谢任何帮助。
答案 0 :(得分:2)
这是使用C#代码创建MS Access表的最佳方法。
public string con_string;
public OleDbConnection My_conn;// = new OleDbConnection();
public OleDbDataAdapter My_ada;
public OleDbCommand cmd;
public DataSet myds;// = new DataSet();
public void Make_Connention()
{
{
con_string = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =";
con_string += AppDomain.CurrentDomain.BaseDirectory.ToString() + "<yourdb>.mdb";
}
My_conn = new OleDbConnection();
My_conn.ConnectionString = con_string;
}
public void IF_EXISTS_DELETE_AND_CREATE()
{
try
{
Make_Connention();
string cn = con_string;
OleDbConnection connection = new OleDbConnection(cn);
object[] objArrRestrict;
objArrRestrict = new object[] { null, null, null, "TABLE" };
connection.Open();
DataTable schemaTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, objArrRestrict);
connection.Close();
string[] list;
if (schemaTable.Rows.Count > 0)
{
list = new string[schemaTable.Rows.Count];
int i = 0;
foreach (DataRow row in schemaTable.Rows)
{
list[i++] = row["TABLE_NAME"].ToString();
}
for (i = 0; i < list.Length; i++)
{
if (list[i] == "TEMP")
{
string deletedl = "DROP TABLE TEMP";
using (OleDbConnection conn = new OleDbConnection(cn))
{
using (OleDbCommand cmd = new OleDbCommand(deletedl, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
break;
}
}
}
string ddl = "CREATE TABLE TEMP (ID COUNTER,USERID INTEGER NOT NULL,[ADATE] TEXT(20), [ATIME] TEXT(20))";
using (OleDbConnection conn = new OleDbConnection(cn))
{
using (OleDbCommand cmd = new OleDbCommand(ddl, conn))
{
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
catch (System.Exception e)
{
string ex = e.Message;
}
}
答案 1 :(得分:0)
这是关于“导航窗格(快门栏)”中的导航的Access问题,与您创建表格的方式无关。您可以安全地忽略此问题,因为它是特定于Access且与OleDb
无关