TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
mithun kumar
NA
21
3.6k
i am trying to insert the data from the form to database
Sep 30 2016 3:49 AM
Here i am trying the code to to insert the data from form to database sql server. it should store the data once i click on submit button.
here is the code for submit button i have tried
private void button2_Click(object sender, EventArgs e)
{
string cs = @"Data Source=.;Database=master;Integrated Security=True";
if(textBox1.Text=="")
{
MessageBox.Show("All fields are manditory to Enter");
return;
}
try
{
SqlConnection con = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand("insert into invoice values ("+textBox3.Text+","+textBox4.Text+","+textBox5.Text+","+textBox6.Text+",", con);
cmd.Parameters.AddWithValue("@invoice", textBox1.Text);
cmd.Parameters.AddWithValue("@prepareby", textBox2.Text);
con.Open();
SqlDataAdapter adapt = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapt.Fill(ds);
con.Close();
int count = ds.Tables[0].Rows.Count;
//If count is equal to 1, than show frmMain form
if (count > 0)
{
}
else
{
MessageBox.Show("Submitted Succesful");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Reply
Answers (
2
)
how to run setup on .net framwork 4.0 or all above version i
Regex or best way to simplify the code to extract and append