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
Ikechukwu Daniel
NA
110
21.6k
How to create an update button with c# in Visual Studio
Jan 20 2017 6:23 AM
Hello, I have a table in mysql also that table contains column for an image how do i update my records in mysql database with c# in visual studio. I have used the code below: But when it does not work. If i make any correction it takes me back to the image line saying path cannot be empty.
byte[] imageBt = null;
FileStream fstream = new FileStream(this.txtPicPath.Text, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fstream);
imageBt = br.ReadBytes((int)fstream.Length);
byte[] imageBt1 = null;
FileStream fstream1 = new FileStream(this.txtPicPath1.Text, FileMode.Open, FileAccess.Read);
BinaryReader br1 = new BinaryReader(fstream1);
imageBt1 = br1.ReadBytes((int)fstream1.Length);
string constring = "datasource=localhost;port=3306;username=root;password=natforce123";
string Query = "UPDATE iman_istf.members SET (idcardno = '" + this.textBoxIDCardNo.Text + "', title ='" + this.textBoxTitle.Text + "', firstname ='" + this.textBoxFirstname.Text + "', lastname ='" + this.textBoxLastname.Text + "', stateofoperation ='" + this.comboBoxStateofOperation.Text + "',stateoforigin ='" + this.comboBoxStateofOrigin.Text + "',memberstatus='" + this.comboBoxMemberStatus.Text + "', designation ='" + this.textBoxDesignation.Text + "', sex ='" + this.comboBoxSex.Text + "', dob='" + this.dateTimePickerDOB.Text + "', lga='" + this.textBoxLGA.Text + "', address='" + this.textBoxAddress.Text + "', phoneno='" + this.textBoxPhoneNo.Text + "', idissuedate='" + this.dateTimePickerIDIssueDate.Text + "', appointmentdate='" + this.dateTimePickerAppointmentDate.Text + "', idcard= @IMG, appointmentletter =@IMG1) WHERE idcardno = '" + this.textBoxIDCardNo.Text + "' ;";
MySqlConnection conDatabase = new MySqlConnection(constring);
MySqlCommand cmdDatabase = new MySqlCommand(Query, conDatabase);
MySqlDataReader myReader;
try
{
conDatabase.Open();
cmdDatabase.Parameters.Add(new MySqlParameter("@IMG", imageBt));
cmdDatabase.Parameters.Add(new MySqlParameter("@IMG1", imageBt1));
myReader = cmdDatabase.ExecuteReader();
MessageBox.Show("Updated Successfully!");
while (myReader.Read())
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Reply
Answers (
1
)
How to get the element of array in c#?
Uploaded Picture remains showing in C# form