基础呀,
string newtablecmd;
int cmdresults;
newtablecmd = "CREATE TABLE LookupCodes (code_id  smallint IDENTITY(1,1) PRIMARY KEY CLUSTERED, code_desc  varchar(50) NOT NULL)";// The following two property settings can also be done 
// in the Properties window, but are shown here for completeness.
OleDbCommand1.CommandType = CommandType.Text;
OleDbCommand1.CommandText = newtablecmd;// The connection must be open before you can execute a command.
OleDbConnection1.Open();
cmdresults = OleDbCommand1.ExecuteNonQuery();
OleDbConnection1.Close();
MessageBox.Show("After creating the table, results = " + cmdresults.ToString());

解决方案 »

  1.   

    看看SQL Server联机文档。
    最基础的东西
      

  2.   

    string conectStr = "server = localhost; uid = sa; pwd = 数据库的sa密码 ;database = NorthWind";
       SqlConnection conn = new SqlConnection(conectStr);//建立连接
      
      string select = "select regiondescription from region where regionid = 1"
      SqlCommand cm = new SqlCommand(select,conn);//建立一个查询命令
      conn.open();//打开连接 
      string result = cm.sCommand.ExecuteScalar().ToString();//取回结果,放在result中。
      conn.Close();//关闭连接
      其他的操作都一样,把select的内容换成你想要的sql命令
      然后注意cm的执行方法。如果是删除,或者更新,cm.ExecuteNonQuery();
      建议楼主看Msdn中的System.Data.SqlClient命名空间
      

  3.   

    //连接数据库
    string str = "user id=sa;password=;initial catalog=test;data source=MZW;Connect Timeout=30";
    SqlConnection conn = new SqlConnection(str);
    //付给dataset控件
    string select = "select * from xsxx";
    DataSet ds = new DataSet(); 
    SqlDataAdapter cmm = new SqlDataAdapter(select,conn); 
    cmm.Fill(ds,"xsxx");
    //绑定DataGrid
    DataGrid1.DataSource = ds.Tables["xsxx"].DefaultView;
    DataGrid1.DataBind();
      

  4.   

    //连接数据库
    string str = "user id=sa;password=;initial catalog=test;data source=MZW;Connect Timeout=30";
    SqlConnection conn = new SqlConnection(str);
    //执行command
    string select = "select * from xsxx";
    SqlCommand cmd= new SqlCommand(select,conn); 
    cmd.Connection.Open();
    //付给SqlDataReader
    SqlDataReader myReader;
    myReader = cmd.ExecuteReader();//连接数据库方法
    //在web.config文件中加入下列代码
    <appSettings>
       <add key="contodata" value="user id=sa;password=;initial catalog=test;data source=MZW;Connect Timeout=30"/>
     </appSettings>
    //连接数据库,并且使用名字空间 using System.Configuration;
    string strconn = ConfigurationSettings.AppSettings["contodata"];
    SqlConnection conn = new SqlConnection(strconn);
      

  5.   

    select 列名1,列名2,...,列名n from 表名 where 列名 = '你的条件'
    delete from 表名 where 列名 = '你的条件'
    update 表名 set 列名 = '你的值' where 列名 = '你的条件'
    insert into 表名(列名1,列名2,...,列名n) value(值1,值2,...,值n)
      

  6.   

    取数据
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection("server=localhost;database=northWind;uid=sa;password=194910");
    conn.Open();
    System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select * from customers",conn);
        dt = new System.Data.DataSet();
    da.Fill(dt,"customers");
    conn.Open();
    this.sqlInsertCommand1.CommandText = @"INSERT INTO Customers(CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)";
    this.sqlInsertCommand1.Connection = conn;
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
    // 
    // sqlUpdateCommand1
    // 
    this.sqlUpdateCommand1.CommandText = @"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName, ContactName = @ContactName, ContactTitle = @ContactTitle, Address = @Address, City = @City, Region = @Region, PostalCode = @PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax WHERE (CustomerID = @Original_CustomerID)";
    this.sqlUpdateCommand1.Connection = conn;
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null));

    // sqlDeleteCommand1
    // 
    this.sqlDeleteCommand1.CommandText = @"DELETE FROM Customers WHERE (CustomerID = @Original_CustomerID) ";
    this.sqlDeleteCommand1.Connection = conn;
    this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null));
      

  7.   

    我不是问SQL语句怎么写,我的问题是::在C#语言里面具体怎么实现这几句SQL语句===>>>>>>
      

  8.   

    SqlCommand thisCommand=new SqlCommand("Select ID,username from manage",thisConnection);
    SqlCommand thisCommand=thisConnection.CreateCommand();thisCommand.CommandText="Select ID,username from manage";

    SqlDataReader thisReader=thisCommand.ExecuteReader();

    thisReader=thisCommand.ExecuteReader();

    while(thisReader.Read())
    {

    textBox1.Text+=thisReader["ID"]+"           "+thisReader["UserName"]+"\r\n";
    }thisReader.Close();thisConnection.Close();
    这是一段调用数据库的代码,你可以看到在第一行有一个参数和SQL语句是一样的,就在那个地方。
      

  9.   

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingstoredprocedureswithcommand.asp