try
{
OleDbDataAdapter da2 = new OleDbDataAdapter("Select * from product_class where product_id like '"+myvalue+"___'",sqlcon);
DataSet ds2=new DataSet();
da2.Fill(ds2,"asdf");
dropdownlist.DataSource=ds2.Tables["asdf"];
dropdownlist.DisplayMember="product_text";
dropdownlist.ValueMember="product_id";
dropdownlist.Text="";
}
catch(System.Data.OleDb.OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlcon.Close();
}
{
OleDbDataAdapter da2 = new OleDbDataAdapter("Select * from product_class where product_id like '"+myvalue+"___'",sqlcon);
DataSet ds2=new DataSet();
da2.Fill(ds2,"asdf");
dropdownlist.DataSource=ds2.Tables["asdf"];
dropdownlist.DisplayMember="product_text";
dropdownlist.ValueMember="product_id";
dropdownlist.Text="";
}
catch(System.Data.OleDb.OleDbException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sqlcon.Close();
}
DataRow newRow=new DataRow();
dataset.tables[0].rows.add(newRow);
2、长度限制可以在SQL语句中处理,select substr(长的,0,10)+'...' as 短的 from 表名
DataGridTableStyle ts1 = new DataGridTableStyle();
ts1.MappingName = "mytable";
// Set other properties.
ts1.AlternatingBackColor = Color.LightGray;
DataGridColumnStyle boolCol = new DataGridTextBoxColumn();
boolCol.MappingName = "Productdh";
boolCol.HeaderText = "产品代号";
boolCol.Width = 80;
ts1.GridColumnStyles.Add(boolCol);
if (TablesAlreadyAdded==true)return;
dataGrid1.TableStyles.Add(ts1); // Sets the TablesAlreadyAdded to true so this doesn't happen again.
TablesAlreadyAdded=true;
//相当于格式化风格并显示。
a.ddl.items.add("","fdf","Dfdf");
b.ddl.items.insertat();
第二个问题:
在datagrid的itemdatabound事件做如下判断
if(e.cells[index].text.length>20)
{e.cells[index].text=e.cells[index].text.substring(0,10);}