以前用delphi开发数据库可以使用ADOQuery或者Query,在按钮的click事件下面写如下的代码//事先设置好dbgrid,datesource,query的关系
sql:='select * from tb with(nolock) where a is null';
query1.close;
query1.sql.clear;
query1.sql.add(sql);
query1.open;但是在winforms中不知道要怎么搞,求帮忙,谢谢!说明,之前都是用delphi开发,很熟练,现在想学着用C#来玩玩。谢谢各位了。

解决方案 »

  1.   

    自己google “c# 数据库”
      

  2.   

    亲,不会啊,教教我啊,我google了"C# winform 数据库开发"我喜欢现场教学
      

  3.   

    using(sqlconnection con=new sqlconnection(你的连接字符串))
    {
     string strsql='select * from tb with(nolock) where a is null';
     SqlDataAdapter ad=new SqlDataAdapter(strsql,con);
    dataset ds=new dataset();
    ad.fill(ds)
    }
    跟你上面的效果是一样的,这个是最简单的转变了。
      

  4.   

    好好学习一下ADO.NET。这里给你一小段连接SQL Server的例子,接下来自己去摸吧。
    SqlConnection conn;  // 数据连连接
    SqlCommand cmd;      // SQL指定对象
    SqlDataReader reader;   // 用来读取数据库返回数据的conn = new SqlConnection("连接字符串");
    conn.Open();
    cmd = conn.CreateCommand();
    cmd.CommandText = "select * from tb with(nolock) where a is null";reader = cmd.ExecuteReader();while (reader.Read())  // 如果Read方法返回false,表示数据已经全部取完。
    {
       // 假定tb表有两列,第一列是int,第二列是nvarchar。
       int id;
       string name;   id = reader.GetInt32(0);      // 读取第一列为Int32,也就是int
       name = reader.GetString(1);   // 读取第二列为String。
    }reader.Close();
    conn.Close();
      

  5.   

    DataAdapter是给懒人用的,性能低,强烈建议不要使用。如果嫌写SQL语句麻烦,可以去用ORM,MS自带的有Linq To SQL(仅限SQL Server)和Entity Framework。
      

  6.   


    msdn查了一下,例子一大把。