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
Joel Bwana
NA
24
1.9k
My update function not working
Aug 27 2020 3:59 PM
When I click "View", data from Database populates the form. I click on a field, make changes, click "Update". Update not working. No error! Where is my problem?
Button View
try
{
conn.Open();
index = 0;
//showData(index);
var query =
"select * FROM Questions"
;
//WHERE AuthorizationCode='" + txtauthorizationcode.Text + "'
var cmd =
new
SqlCommand(query, conn);
SqlDataReader dr = cmd.ExecuteReader();
var sSingle =
"Single Choice"
;
var sMultiple =
"Multiple Choice"
;
while
(dr.Read())
{
if
(dr.GetString(9) == sSingle)
{
grpmultipleanswers.Visible =
false
;
grpsingleanswers.Visible =
true
;
txtquestion.Text = dr.GetString(2);
//txtquestion.Text = dr.GetValue(2).ToString();
txta.Text = dr.GetString(3);
txtb.Text = dr.GetString(4);
txtc.Text = dr.GetString(5);
txtd.Text = dr.GetString(6);
cmbqtype.SelectedItem = dr.GetString(9);
cmbcomplexity.SelectedItem = dr.GetString(10);
lblscore.Text = dr.GetInt32(11).ToString();
lblquestionno.Text =
"Question "
+ dr.GetInt32(0).ToString();
}
if
(dr.GetString(9) == sMultiple)
{
grpmultipleanswers.Visible =
true
;
grpsingleanswers.Visible =
false
;
txtquestion.Text = dr.GetString(2);
cmbqtype.SelectedItem = dr.GetString(9);
cmbcomplexity.SelectedItem = dr.GetString(10);
lblscore.Text = dr.GetInt32(11).ToString();
//lblquestion.Text = dr.GetInt32(0).ToString();
lblquestionno.Text =
"Question "
+ dr.GetInt32(0).ToString();
//lblquestion.Text = "Question" + " " + dr.GetInt32(0).ToString();
txtchkchoiceA.Text = dr.GetString(3);
txtchkchoiceB.Text = dr.GetString(4);
txtchkchoiceC.Text = dr.GetString(5);
txtchkchoiceD.Text = dr.GetString(6);
txtchkchoiceE.Text = dr.GetString(7);
txtchkchoiceF.Text = dr.GetString(8);
}
}
//btnfirst.Hide();
btnview.Hide();
btnupdate.Show();
conn.Close();
}
catch
(Exception ex)
{
MessageBox.Show(
"Error Occured"
+ ex);
}
Button Update
try
{
SqlConnection conn =
new
SqlConnection(@
"Data Source = (LocalDB)\MSSQLlocaldb; Initial Catalog = AdminAuthentication; Integrated Security = True"
);
var query =
"update Questions Set QText= @QText, ChoiceA=@ChoiceA, ChoiceB=@ChoiceB,ChoiceC=@ChoiceC,ChoiceD=@ChoiceD, ChoiceE=@ChoiceE,ChoiceF=@ChoiceF,QType=@QType,QComplexity=@QComplexity,QPoints=@QPoints,AuthorizationCode=@AuthorizationCode,Exhibit=@exhibit WHERE QID=@QID"
;
var cmd =
new
SqlCommand(query, conn);
conn.Open();
cmd.Parameters.AddWithValue(
"@QID"
, SqlDbType.Int).Value = lblquestion.Text;
cmd.Parameters.AddWithValue(
"@QText"
, SqlDbType.VarChar).Value = txtquestion.Text;
cmd.Parameters.AddWithValue(
"@ChoiceA"
, SqlDbType.VarChar).Value = txta.Text;
cmd.Parameters.AddWithValue(
"@ChoiceB"
, SqlDbType.VarChar).Value = txtb.Text;
cmd.Parameters.AddWithValue(
"@ChoiceC"
, SqlDbType.VarChar).Value = txtc.Text;
cmd.Parameters.AddWithValue(
"@ChoiceD"
, SqlDbType.VarChar).Value = txtd.Text;
cmd.Parameters.AddWithValue(
"@ChoiceE"
, SqlDbType.VarChar).Value = txtchkchoiceE.Text;
cmd.Parameters.AddWithValue(
"@ChoiceF"
, SqlDbType.VarChar).Value = txtchkchoiceF.Text;
cmd.Parameters.AddWithValue(
"@QPoints"
, SqlDbType.Int).Value = lblscore.Text;
cmd.Parameters.AddWithValue(
"@QType"
, SqlDbType.VarChar).Value = cmbqtype.SelectedItem;
cmd.Parameters.AddWithValue(
"@QComplexity"
, SqlDbType.VarChar).Value = cmbcomplexity.SelectedItem;
cmd.Parameters.AddWithValue(
"@AuthorizationCode"
, SqlDbType.Int).Value = txtauthorizationcode.Text;
cmd.Parameters.Add(
new
SqlParameter(
"@exhibit"
, images));
cmd.ExecuteNonQuery();
txtquestion.Clear();
txta.Clear();
txtb.Clear();
txtc.Clear();
txtd.Clear();
txtchkchoiceA.Clear();
txtchkchoiceB.Clear();
txtchkchoiceC.Clear();
txtchkchoiceD.Clear();
txtchkchoiceE.Clear();
txtchkchoiceF.Clear();
lblquestion.Text =
""
;
lblquestionno.Text =
""
;
lblscore.Text =
""
;
cmbqtype.SelectedItem =
null
;
cmbcomplexity.SelectedItem =
null
;
//MessageBox.Show("Data succefully updated");
//this.Hide();
//AdminPanel ap = new AdminPanel();
//ap.Show();
////what next?
conn.Close();
}
catch
(Exception ex)
{
MessageBox.Show(
"Error Occured"
+ ex);
}
Reply
Answers (
1
)
About classes of visual c++
how to configure my excel to default all cells to text.