Click here to Skip to main content
15,906,567 members
Home / Discussions / C#
   

C#

 
AnswerRe: unable to insert data Pin
Simon_Whale4-Jul-13 22:02
Simon_Whale4-Jul-13 22:02 
GeneralRe: unable to insert data Pin
new to c# programming4-Jul-13 22:49
new to c# programming4-Jul-13 22:49 
QuestionC# shuffle one column out of two Pin
yandroide4-Jul-13 10:14
yandroide4-Jul-13 10:14 
AnswerRe: C# shuffle one column out of two Pin
Eddy Vluggen4-Jul-13 10:21
professionalEddy Vluggen4-Jul-13 10:21 
AnswerRe: C# shuffle one column out of two Pin
thanh_bkhn4-Jul-13 19:03
professionalthanh_bkhn4-Jul-13 19:03 
QuestionSplit string in multiple strings Pin
Sachin k Rajput 4-Jul-13 1:46
Sachin k Rajput 4-Jul-13 1:46 
AnswerRe: Split string in multiple strings PinPopular
Richard Deeming4-Jul-13 2:48
mveRichard Deeming4-Jul-13 2:48 
QuestionHow to use “Client Application Services” in Windows Forms Applications even in offline / disconnected mode Pin
devenv.exe3-Jul-13 23:21
professionaldevenv.exe3-Jul-13 23:21 
AnswerRe: How to use “Client Application Services” in Windows Forms Applications even in offline / disconnected mode Pin
Eddy Vluggen4-Jul-13 0:28
professionalEddy Vluggen4-Jul-13 0:28 
GeneralRe: How to use “Client Application Services” in Windows Forms Applications even in offline / disconnected mode Pin
devenv.exe4-Jul-13 1:10
professionaldevenv.exe4-Jul-13 1:10 
GeneralRe: How to use “Client Application Services” in Windows Forms Applications even in offline / disconnected mode Pin
Eddy Vluggen4-Jul-13 2:48
professionalEddy Vluggen4-Jul-13 2:48 
Questionexecute query Pin
new to c# programming3-Jul-13 20:25
new to c# programming3-Jul-13 20:25 
AnswerRe: execute query Pin
Amol_B3-Jul-13 20:46
professionalAmol_B3-Jul-13 20:46 
GeneralRe: execute query Pin
new to c# programming3-Jul-13 22:57
new to c# programming3-Jul-13 22:57 
GeneralRe: execute query Pin
new to c# programming4-Jul-13 0:21
new to c# programming4-Jul-13 0:21 
AnswerRe: execute query Pin
Amol_B4-Jul-13 0:31
professionalAmol_B4-Jul-13 0:31 
GeneralRe: execute query Pin
new to c# programming4-Jul-13 1:03
new to c# programming4-Jul-13 1:03 
GeneralRe: execute query Pin
Amol_B4-Jul-13 18:59
professionalAmol_B4-Jul-13 18:59 
AnswerRe: execute query Pin
Pete O'Hanlon3-Jul-13 20:58
mvePete O'Hanlon3-Jul-13 20:58 
GeneralRe: execute query Pin
Mycroft Holmes3-Jul-13 22:23
professionalMycroft Holmes3-Jul-13 22:23 
GeneralRe: execute query Pin
new to c# programming3-Jul-13 22:58
new to c# programming3-Jul-13 22:58 
GeneralRe: execute query Pin
new to c# programming4-Jul-13 0:20
new to c# programming4-Jul-13 0:20 
private void button1_Click(object sender, EventArgs e)
{
resetLabels();


using (SqlConnection cn = new SqlConnection())
{
cn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\patientdb.mdf;Integrated Security=True;User Instance=True";
cn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "select convert(varchar(50),getdate(),105) as date";
SqlDataReader sdr = cmd.ExecuteReader();

while (sdr.Read())
{
date = sdr["date"].ToString();
}
sdr.Close();
setPatientidtxt();
if (updateflag)
{
cmd.CommandText = "update Patient set" +
" name=@FirstName,surname=@LastName,age=@Age,city=@City,gender=@Gender,allergy=@Allergy,phoneno=@ContactNo,consultingfees=@Fees,note=@Note,date=@Date,time=@Time" +
" where patientid=@Patientid";
cmd.Parameters.AddWithValue("@patientid",textBox1.Text);
}
else
{
cmd.CommandText = "insert into patient values" +
"(@FirstName,@LastName,@Age,@City,@Gender,@Allergy,@ContactNo,@Fees,@Note,@Date,@Time)";
}
cmd.Parameters.AddWithValue("@FirstName", textBox2.Text);
cmd.Parameters.AddWithValue("@LastName", textBox3.Text);
cmd.Parameters.AddWithValue("@Age", textBox4.Text);
cmd.Parameters.AddWithValue("@City", textBox5.Text);
//radio button



if (radioButton1.Checked == true)
{
cmd.Parameters.AddWithValue("@Gender", radioButton1.Text);
}
else
{
cmd.Parameters.AddWithValue("@Gender", radioButton2.Text);
}
if (radioButton3.Checked == true)
{
cmd.Parameters.AddWithValue("@Allergy", radioButton3.Text);
}
else
{
cmd.Parameters.AddWithValue("@Allergy", radioButton4.Text);

}

cmd.Parameters.AddWithValue("@ContactNo", textBox6.Text);
cmd.Parameters.AddWithValue("@Fees", textBox7.Text);
cmd.Parameters.AddWithValue("@Note", textBox8.Text);
cmd.Parameters.AddWithValue("@Date", System.DateTime.Now.ToShortDateString());
cmd.Parameters.AddWithValue("@Time", System.DateTime.Now.ToLongTimeString());
// here the exception error (break) is comming at ExecuteNonQuery)

cmd.ExecuteNonQuery();

button4.Enabled = true;
label11.Visible = true;
label4.Visible = true;

timer1.Start();


}

}






I am getting an error as :

"An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: Column name or number of supplied values does not match table definition."
and sequence of columns in my table is (patientid,name,surname,age,city,gender,allergy,phoneno,consultingfees,note,date,time)
i am wondering where is sequence wrong in my code. Frown | :( .
AnswerRe: execute query Pin
Richard MacCutchan3-Jul-13 21:02
mveRichard MacCutchan3-Jul-13 21:02 
QuestionAlign Text Vertically For PDF Document Pin
reethu_test3-Jul-13 15:25
reethu_test3-Jul-13 15:25 
AnswerRe: Align Text Vertically For PDF Document Pin
Garth J Lancaster3-Jul-13 16:12
professionalGarth J Lancaster3-Jul-13 16:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.