public partial class frmMaterial : Form { public frmMaterial() { InitializeComponent(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = "Data Source=ASA-PC; Initial Catalog=Material_database; User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=60"; connection.Open(); SqlCommand command = new SqlCommand("select * from mat_utiAndtrans", connection); DataTable ds = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(command); cmbcode.DataSource = ds; da.Fill(ds); cmbcode.DisplayMember = "Code"; cmbcode.ValueMember = "Code"; } private void btnsearch_Click(object sender, EventArgs e) { if (cmbcode.SelectedIndex >= 0) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = "Data Source=ASA-PC; Initial Catalog=Material_database; User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=60"; connection.Open(); DataSet dl = new DataSet(); string a = cmbcode.SelectedValue.ToString(); SqlCommand com = new SqlCommand("select * from mat_utiAndtrans where Code='" + a + "'", connection); DataSet dts = new DataSet(); SqlDataAdapter da = new SqlDataAdapter(com); dataGridView1.DataSource = dts; da.Fill(dts); dataGridView1.DataMember = dts.Tables[0].ToString(); }
public partial class frmMaterial : Form { public frmMaterial() { InitializeComponent(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = "Data Source=ASA-PC; Initial Catalog=Material_database; User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=60"; connection.Open(); SqlCommand command = new SqlCommand("select * from mat_utiAndtrans", connection); DataTable ds = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(command); cmbcode.DataSource = ds; da.Fill(ds); cmbcode.DisplayMember = "Code"; cmbcode.ValueMember = "Code"; } private void btnsearch_Click(object sender, EventArgs e) { if (cmbcode.SelectedIndex >= 0) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = "Data Source=ASA-PC; Initial Catalog=Material_database; User ID=sa;Password=sa;Integrated Security=false;Connect Timeout=60"; connection.Open() string a = cmbcode.SelectedValue.ToString(); SqlCommand com = new SqlCommand("select * from mat_utiAndtrans where Code='" + a + "'", connection); SqlDataAdapter da = new SqlDataAdapter(com); DataTable dt = new DataTable(); da.Fill(dts); dataGridView1.DataSource = dt; }
cmbcode.DisplayMember = "Code"; cmbcode.ValueMember = "Code"; da.Fill(ds); // Fill the data first and then assign it to a control cmbcode.DataSource = ds;
da.Fill(dts); dataGridView1.DataSource = dts; //dataGridView1.DataMember = dts.Tables[0].ToString();
string com=sqlQuery; SqlDataAdapter da= new SqlDataAdapter(com,connection);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)