就在你的的 button1_Click 事件件裡就可以寫...你想怎麼用就怎麼寫,寫在在 類裡面,子函數 裡面都可以...
解决方案 »
- C#调用BAT批处理文件连接sqlplus批量执行sql语句
- 本机程序"互联网"(分享)
- 【求助】关于DataBindings在Format后,ConvertEventHandler不能触发的问题
- 请教各位:开发这样的小程序需要多长时间。
- 请问VC#2005中有没有比较好用的表格控件?没有关联数据库,只是简单显示一些很少的数据
- DllImport 调用问题
- DragDrop问题,求段代码拖放textBox文字到另一个textBox中
- 急:未将对象引用到对象的实例
- 如何得到一个目录的大小(关键要包含所有的子目录),有什么简单办法吗?
- 不知道怎样调用msdn里面的例子函数!!!!在线等待!!!!
- C#程序怎样调用windows IPA?
- 如何让datagrid的列的宽度固定,不能被拖动?
最好先找点书看看
using System.Data;
using System.Data.SqlClient;namespace jingchen.bizLogic
{
/// <summary>
/// DBcaiw 的摘要说明。
/// </summary>
public class DBcaiw
{
public DBcaiw()
{
//
// TODO: 在此处添加构造函数逻辑
//
} public DataView select_caiwzhk1(string hetbh,string chulyf)
{
SqlConnection myConn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["connectionString"]);
SqlCommand myCommand=new SqlCommand("select jine,fachshl,id,shuinjzh,fahrq,tuipshl,kaipyf,shuindj,cheh,chucbh,chulyf,tidh from caiwzhk where hetbh=@m_hetbh and chulyf=@m_chulyf" ,myConn);
myCommand.Parameters.Add(new SqlParameter("@m_hetbh", SqlDbType.NVarChar ,50)).Value=hetbh;
myCommand.Parameters.Add(new SqlParameter("@m_chulyf", SqlDbType.NVarChar ,50)).Value=chulyf;
SqlDataAdapter myda=new SqlDataAdapter();
myda.SelectCommand=myCommand;
DataSet ds = new DataSet();
myda.Fill(ds, "caiwzhk");
return ds.Tables["caiwzhk"].DefaultView; }
}
}
调用 private void button1_Click(object sender, EventArgs e)
{
//SQL语句我应该写在哪里,哪个控件属性里。用了dataSet1和dataconnector1 2个控件,
new jingchen.bizLogic.DBcaiw().select_caiwzhk1(string hetbh,string chulyf) ;
}
和查询,交易的部分,可以写Code非常快,connecting不会乱
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlConnection sqlConnection1;
protected System.Data.SqlClient.SqlCommand sqlCommand1;
protected System.Data.DataSet dataSet1;
string selectId;sqlConnection1=new System.Data.SqlClient.SqlConnection("server=(local);user id=sa; password=863; database=jcdt;");
if(!IsPostBack)
{
this.Validate();
}
BindData();
public void BindData()
{
string strCommand1="select * from dt";
sqlDataAdapter1=new System.Data.SqlClient.SqlDataAdapter(strCommand1,sqlConnection1);
dataSet1=new DataSet();
sqlDataAdapter1.Fill(dataSet1,"dt");
DataGrid1.DataSource=dataSet1.Tables["dt"].DefaultView;
DataGrid1.DataBind();
}以后需要再次绑定数据库里面的数据时,只需重新调用BindData()就可以了
SqlConnection conn = new SqlConnection("连接字符串");
conn.Open();
//声明SqlCommand
SqlCommand acmd = new SqlCommand("Sql语句",conn);
//执行SqlCommand
acmd.ExecuteNonQuery();
//关闭连接
conn.Close();
Dim InsertCmd As String = "select * from admin where username='" + username.Text + "'"
再对sqlcommand赋SQL语句啊