Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
2
Answers
How to update datagridview cell value in Windows form c#
Jyoti Jodha
7y
246
1
Reply
Don't show any error....
cmd =
new
SqlCommand(
"update cmpny_dtl set c_name=@c_name ,adrs=@adrs, c_phone=@c_phone, logo=@logo , state_id=@state_id where id=@id"
, con);
con.Open();
cmd.Parameters.AddWithValue(
"@id"
, id);
cmd.Parameters.AddWithValue(
"@c_name"
, CmpnyName_txt.Text);
cmd.Parameters.AddWithValue(
"@adrs"
, Adrs_txt.Text);
cmd.Parameters.AddWithValue(
"@c_phone"
, CmpnyPhone_txt.Text);
cmd.Parameters.AddWithValue(
"@state_id"
, STATE_comboBox.SelectedValue);
if
(pictureBox1.Image !=
null
)
{
MemoryStream ms =
new
MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte
[] photo = ms.ToArray();
cmd.Parameters.AddWithValue(
"@logo"
, photo);
}
else
{
cmd.Parameters.AddWithValue(
"@logo"
, (pictureBox1.Image ==
null
) ? (
object
)DBNull.Value : pictureBox1.Image).SqlDbType = SqlDbType.Image;
}
int
k = cmd.ExecuteNonQuery();
cmd.ExecuteNonQuery();
con.Close();
if
(k > 0)
{
MessageBox.Show(k.ToString() +
"Record Inserted Successfully"
);
DisplayData();
ClearData();
}
else
{
MessageBox.Show(
"A record with a user name already exists"
, CmpnyName_txt.Text);
}
Post
Reset
Cancel
Answers (
2
)
Next Recommended Forum
Textbox validation for amount
System.InvalidCastException: 'Specified cast is not valid.'