开发者

C# change mdb filed data type to memo and save it

I would like to change the data type in my db from "Text" to "Memo". first o开发者_运维技巧f all, I didnt find the "Memo" data type in c#. second: I got the following code to execute command in the db:

    public void SQLCommand(String strSQL)
    {
        OleDbConnection objConnection = null;
        OleDbCommand objCmd = null;
        String strConnection;
        strConnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + "\\tasks.mdb";
        objConnection = new OleDbConnection(strConnection);
        objConnection.ConnectionString = strConnection;
        objConnection.Open();
        objCmd = new OleDbCommand(strSQL, objConnection);
        objCmd.ExecuteNonQuery();
        objConnection.Close();
        UpdateListView();
    }

how can I change the 3rd column's data type and save it? I can change the data type when form_load with this function:

    public void tst()
    {
        conn.Open();
        DataSet ds = new DataSet();
        OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * from Tasks", conn);
        adapter.Fill(ds);
        DataTable dt = ds.Tables[0];
        dt.Columns[3].DataType = System.Type.GetType("System.String");
        conn.Close();
    }

but with this function, it change to the data type to string > and I want memo. also this function is no good since I need to run it everytime and if I change it permanently to memo I will just have to make a little if at the begining.

~Thanks.


  1. String in C# is the equivalent of both Text and Memo in that it supports texts of either length.

  2. If I understand the question correctly I think you're misunderstanding what you're actually doing in your code. When you set the DataType of the column, you're not changing the database in any way, you are just changing the datatype of a column in the DataTable instance that you've created.

If you actually want to change the structure of the database the best way would probably be to do it manually in Access, since I'm not sure if that's really supported in ADO.Net (I suppose you might be able to do it using ALTER statements). Otherwise you might be able to do it using DAO which used to be the Access/Jet way of doing things like that, but that was deprecated quite a while ago so might not work well in .Net.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜