会员姓名
原卡号
旧卡号
密码
查询
C#的,应该连接数据库再写查询语句吧,就是不会写连接数据库的代码,没头绪,大家帮忙,好吧
namespace MASTER_ANCN
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnsearch_Click(object sender, EventArgs e)
{
using System. date.SQLClient;
SQLConnection SQLConn = new Connection();
string sql=Select *From ;
SQLConn. ConnectionString="myconnectionstring";
SQLConn. open();
}
}
}
应该缺了很多东西,不知道该怎么写了,不会
------解决方案--------------------------------------------------------
- C# code
public DataTable GetDataTable(string sql) { SQLConnection conn = new OleDbConnection(@"连接字符串"); SQLDbDataAdapter SQLda = new OleDbDataAdapter(sql, conn); DataTable dt = new DataTable(); SQLda.Fill(dt); return dt; }
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
private static DataSet SelectRows(DataSet dataset,
string connectionString,string queryString)
{
using (SqlConnection connection =
new SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(
queryString, connection);
adapter.Fill(dataset);
return dataset;
}
}
楼主买本书,好好看看吧
------解决方案--------------------------------------------------------
- C# code
string ConStr = "Persist Security Info=False;Initial Catalog=FilmManger;"; ConStr += "Data Source=.;Integrated Security=SSPI;";//连接串不懂自己去看。 SqlConnection myCon = new SqlConnection(ConStr); string ComStr = "select EmployeeID,Name,Sex,Age,Address,Tile from employee"; SqlCommand myCom = new SqlCommand(ComStr, myCon); SqlDataAdapter myDA = new SqlDataAdapter(); myDA.SelectCommand = myCom; myCon.Open(); DataSet myDS = new DataSet(); myDA.Fill(myDS, "employee"); DataView myDV = myDS.Tables["employee"].DefaultView; myDV.Sort = "age"; this.GridView1.DataSource = myDV; this.GridView1.DataBind(); myCon.Close();
------解决方案--------------------------------------------------------
去下载dbhelper数据操作类!都写好的
------解决方案--------------------------------------------------------
- C# code
private static SqlConnection GetConnection() { string myStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); SqlConnection myConn = new SqlConnection(myStr); return myConn; }try { SqlConnection myConn = GetConnection(); myConn.Open(); SqlCommand myComm_1 = new SqlCommand(sqlstr_1, myConn); SqlCommand myComm_2 = new SqlCommand(sqlstr_2, myConn); myComm_1.ExecuteNonQuery(); myComm_2.ExecuteNonQuery(); myConn.Close(); flag = true; } catch (Exception ex) { logger.Error(ex); throw; }