Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
single database with different table
Durga Velusamy
Mar 26 2015 2:29 AM
671
Reply
public Form1()
{
InitializeComponent();
BasDataSet dataSet = new BasDataSet();
BasDataSetTableAdapters.deviTableAdapter adapter = new BasDataSetTableAdapters.deviTableAdapter();
adapter.Fill(dataSet.devi);
comboBox1.DataSource = dataSet.devi;
comboBox1.DisplayMember = "CustomerId";
}
private void button1_Click(object sender, EventArgs e)
{
{
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
SqlCommand cmd1 = new SqlCommand("insert into devi Values('" + comboBox1.Text + "',+'" + comboBox2
.Text + "','" + comboBox3.Text + "','" + comboBox4.Text + "','" + comboBox5.Text + "','" + comboBox6.Text + "','" + comboBox7.Text + "')", con);
cmd1.ExecuteNonQuery();
con.Close();
MessageBox.Show("Added Successfully");
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
comboBox4.Text = "";
comboBox5.Text = "";
comboBox6.Text = "";
comboBox7.Text = "";
}
in the second form i have same database with different table name
instead of devi table i have table name as durga. this form use the bas database and devi table name its working.
but in the 2nd form bas database and durga table its not working. why? just i have change
the table only in the binding code it shows error at i have drag red background
public Form1()
{
InitializeComponent();
BasDataSet dataSet = new BasDataSet();
BasDataSetTableAdapters.durgaTableAdapter adapter = new BasDataSetTableAdapters.durgaTableAdapter();
adapter.Fill(dataSet.durga);
comboBox1.DataSource = dataSet.durga;
comboBox1.DisplayMember = "CustomerId";
}
private void button1_Click(object sender, EventArgs e)
{
{
SqlConnection con = new SqlConnection(@"server=CSE-PC; integrated security=true; Database=Bas");
con.Open();
SqlCommand cmd1 = new SqlCommand("insert into durga Values('" + comboBox1.Text + "',+'" + comboBox2
.Text + "','" + comboBox3.Text + "','" + comboBox4.Text + "','" + comboBox5.Text + "','" + comboBox6.Text + "','" + comboBox7.Text + "')", con);
cmd1.ExecuteNonQuery();
con.Close();
MessageBox.Show("Added Successfully");
comboBox1.Text = "";
comboBox2.Text = "";
comboBox3.Text = "";
comboBox4.Text = "";
comboBox5.Text = "";
comboBox6.Text = "";
comboBox7.Text = "";
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
different ways of using combobox
windowform ,ado.net and sql server 2008