SQL几种简单的语法

 

代码
private void button1_Click(object sender, EventArgs e)
{
string strconn = "Data Source=localhost;Initial Catalog=Large;Persist Security Info=True;User ID=sb;Password=juanjuan";
string queryString = "SELECT * FROM news WHERE name = @uname";
SqlDataAdapter adapter
= new SqlDataAdapter(queryString, strconn);
adapter.SelectCommand.Parameters.Add(
"@uname", SqlDbType.NVarChar, 50, "name").Value = textBox1.Text; //搜索 用where

new SqlCommandBuilder(adapter);
DataSet ds
= new DataSet();
adapter.Fill(ds,
"yyqtab");
DataTable dtable
= ds.Tables["yyqtab"];
/*textBox2.Text = (string)ds.Tables["yyqtab"].Rows[0][1]; //提取
textBox2.Text = (string)ds.Tables["yyqtab"].Rows[0][1];//
*/
ds.Tables[
"yyqtab"].Rows[0].Delete(); // 搜索数据库里的数据并删除所搜到的东西

/*DataRow workRow = dtable.NewRows(); //插入
workRow[0] = textBox1.Text ;
workRow[1] = textBox2.Text;
dtable.Rows.Add(workRow);//
*/
/*ds.Tables["yyqtab"].Rows[0][0] = textBox1.Text; //更新
ds.Tables["yyqtab"].Rows[0][1] = textBox2.Text;
*/
//ds.Tables["yyqtab"].Rows[0].Delete(); // 删除


adapter.Update(ds,
"yyqtab");


/*textBox1.Clear();
textBox2.Clear();
*/
//this.Close();

//string a = @"F:\g.txt";
//string s = textBox1.Text;
//File.WriteAllText(queryString, s);

}

设计视图

数据库为Large

 

posted @ 2010-03-21 23:58  平凡人生  阅读(217)  评论(0编辑  收藏  举报