各位大大們好
因為在下對於IDE和SQL之間的操作真的不是很熟
這個問題我花了不少時間還是無法理解
肯請大家給我釣竿就好
魚的部分我再慢慢釣
對SQL操作的程式碼如下
我希望能透過這個程式碼撈取資料繫結至ComBoBox
public class mysql
{
public static string MYSQLConnString = "datasource = xxx;database=x;username = xxx; password = xx";
public static MySqlConnection OpenSqlConn(string constr)
{
MySqlConnection icn = new MySqlConnection();
icn.ConnectionString = constr;
if (icn.State == ConnectionState.Open) icn.Close();
icn.Open();
return icn;
}
public static DataTable getDataTable(string SqlString)
{
DataTable myDataTable = new DataTable();
MySqlConnection icn = null;
icn = OpenSqlConn(MYSQLConnString);
MySqlCommand isc = new MySqlCommand();
MySqlDataAdapter da = new MySqlDataAdapter(isc);
try
{
isc.Connection = icn;
isc.CommandText = SqlString;
isc.CommandTimeout = 600;
DataSet ds = new DataSet();
ds.Clear();
da.Fill(ds);
myDataTable = ds.Tables[0];
if (icn.State == ConnectionState.Open) icn.Close();
return myDataTable;
}
catch (Exception ex)
{
throw (ex);
}
}
}
}
謝謝大家
DataTable dt = mysql.getDataTable("select ....from....");
combo.DataSource = dt;
combo.DisplayMember = "Title";
combo.ValueMember = "Value";