今天的一些收获

11:01 2006-8-31
怎样在c#获取一个access数据库的全部数据表?
我想选择一个数据库,然后再combox中列出这个数据库的所有表的名称,请问怎么实现?

msdn上有这些代码,能否给解释一下:

using System;
using System.Data;
using System.Data.OleDb;

class Class1
{
    static void Main()
    {
        string x = "Provider=SQLOLEDB;Data Source=(local);Initial Catalog=AdventureWorks;"
            + "Integrated Security=SSPI";
        GetSchemaTable(x);
        Console.ReadLine();
    }

    static DataTable GetSchemaTable(string connectionString)
    {
        using (OleDbConnection connection = new
                   OleDbConnection(connectionString))
        {
            connection.Open();
            DataTable schemaTable = connection.GetOleDbSchemaTable(
                OleDbSchemaGuid.Tables,
                new object[] { null, null, null, "TABLE" });
            return schemaTable;
        }

循环 schemaTable 取出 schemaTable .Rows[i]["TABLE_NAME"].ToString();    ,绑定到combox

12:16 2006-8-31
ComboBox 的使用

设置当前列出的项:.SelectedIndex=i      //i从0开始
添加列表项:.Items.Add();
获取当前组合框列出的项目:.SelectedItem.ToString();

SelectionChangeCommitted事件:当从下拉列表中选择项而下拉列表关闭时发生。

12:41 2006-8-31
关于数据库的操作:
1.连接数据库:
          OleDbConnection Conn = new OleDbConnection();
                 Conn.ConnectionString = " Provider = Microsoft.Jet.OLEDB.4.0; Data Source=" + DataBasePath; //DataBasePath为数据库所在的路径,可以用openFileDialog来选择数据文件。
2.得到记录集:
   string sql = "select # from " + DataTable;   //DataTable为上面数据库中的一个数据表
                 OleDbCommand objCmd = new OleDbCommand(sql,Conn);
                 OleDbDataReader objDR;
                 objDR = objCmd.ExecuteReader();

13:22 2006-8-31
文本文件的IO处理:
1.打开:
                int index = openFileDialog1.FileName.LastIndexOf("//");
                FileName = openFileDialog1.FileName.Substring(index + 1);   //前两句得到的是用openFileDialog选择的文件的文件名
                System.IO.FileStream FS = new System.IO.FileStream(FileName, System.IO.FileMode.Open);
                System.IO.StreamReader SR = new System.IO.StreamReader(FS);
                textBox1.Text = SR.ReadToEnd();
2.写入:
                        System.IO.StreamWriter sw = new System.IO.StreamWriter(FileName);
                        sw.Write(textBox1.Text);

13:28 2006-8-31
记事本的处理技巧:
1.删除命令的实现:
            if (textBox1.SelectedText != "")
            {
                textBox1.SelectedText = "";
            }
2.撤销命令的实现:
            if (textBox1.CanUndo == true)
            {
                textBox1.Undo();
                textBox1.ClearUndo();
            }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值