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
Abhay Singhania
NA
32
14.6k
Values Are Not Getting Stored From Combo box to Data Base
May 21 2015 12:49 AM
I have a combo box named cmbboxreceivedby, from this combobox i m selecting a value, but the selected value is not stored in the data base.
it shows System.Data.DataRowView. here is the print screen of data base
and here is my code
private void cmbboxreceivedby_SelectedIndexChanged(object sender, EventArgs e)
{
name = cmbboxreceivedby.SelectedItem.ToString();
}
private void btnadddonor_Click(object sender, EventArgs e)
{
if (txtaddress.Text == "" || txtcontactnum.Text == "" || txtmessage.Text == "" || txtpatientage.Text == "" || txtpatientname.Text == "" || txtpreviousdonors.Text == "")
{
MessageBox.Show("Fields Cannot Be Left Empty", "Error..!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
SqlConnection coonn = new SqlConnection(con);
SqlCommand sqlcmd = new SqlCommand("insert into Donors (Name,Address,Sex,MobileNum,BloodGroup,ReceivedBy,Comments,PreviousDonors) values (@name,@add,@sex,@mblnum,@bldgrp,@rcvdby,@cmt,@prvsdnrs)", coonn);
sqlcmd.Parameters.Add(new SqlParameter("@name", txtpatientname.Text));
sqlcmd.Parameters.Add(new SqlParameter("@add", txtaddress.Text));
sqlcmd.Parameters.Add(new SqlParameter("@sex", comboBoxGender.SelectedItem.ToString()));
sqlcmd.Parameters.Add(new SqlParameter("@mblnum", txtcontactnum.Text));
sqlcmd.Parameters.Add(new SqlParameter("@bldgrp", comboxbldgrp.SelectedItem));
sqlcmd.Parameters.Add(new SqlParameter("@rcvdby", name));
sqlcmd.Parameters.Add(new SqlParameter("@cmt", txtmessage.Text));
sqlcmd.Parameters.Add(new SqlParameter("@prvsdnrs", txtpreviousdonors.Text));
SqlCommand sqlcmd2 = new SqlCommand("update [BloodStock] set [Quantity] = Quantity + 1 where Blood_Group = @blood_group", coonn);
sqlcmd2.Parameters.Add(new SqlParameter("@blood_group", comboxbldgrp.SelectedItem));
coonn.Open();
sqlcmd.ExecuteNonQuery();
sqlcmd2.ExecuteNonQuery();
coonn.Close();
coonn.Dispose();
MessageBox.Show("Donor Added", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
please help..
Reply
Answers (
5
)
How Can I Sort Employee Base On True Or False Value
validation of user input instantly when user leaves the text