Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SqlConnection objCon = new SqlConnection(@"Data Source=hyd-npulivarthy;Initial Catalog=projecthotel;Integrated Security=True");

SqlCommand objCmd = new SqlCommand();
objCmd.Connection = objCon;

string query = ("insert into Reservation (@Code, @Status,@Guest Name,@Guest Email,@Guest Phone No,@Checkin,@Check Out,@Adult No,@Child No,@Infant No,@Net Total,@Discount,@Tax,@Total,@Paid")values( '" +textBox1.Text+ "',"' + comboBox2.SelectedValue + "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "')");

objCon.Open();
int j = objCmd.ExecuteNonQuery();
if (j > 0)
{

MessageBox.Show("Record Inserted","www.codingresolved.com");
dataGridView1.Rows.Clear();
}

objCon.Close();

Form1 form1 = new Form1();
form1.Show();


The error comming in
)values( '" +textBox1.Text+ "',"' + comboBox2.SelectedValue + "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "')");..
can u plz rectify
Posted

You should rewrite you whole sql Using Parameterized queries to prevent SQL Injection Attacks in SQL Server[^]
That will also avoid the messy and confusing quotes problem.
 
Share this answer
 
Check the no.of columns and values your passing are same count and all are string datatype?

try this

string query = "insert into Reservation (@Code, @Status,@Guest Name,@Guest Email,@Guest Phone No)values( '" +textBox1.Text+ "',"' + comboBox2.SelectedValue + "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "')";
 
Share this answer
 
You are missing some quotes near values and combobox

try this
C#
string query = ("insert into Reservation (@Code, @Status,@Guest Name,@Guest Email,@Guest Phone No,@Checkin,@Check Out,@Adult No,@Child No,@Infant No,@Net Total,@Discount,@Tax,@Total,@Paid)+values( '" +textBox1.Text+ "','" + comboBox2.SelectedValue + "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "','" +textBox1.Text+ "')");
 
Share this answer
 
Whats the error? can you post?
 
Share this answer
 
Comments
hilbert hussen 23-Apr-14 9:03am    
too many literal characters
before values ;expected

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900