Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
the cod for selecte
cmd.CommandText = "SELECT input_tb.f_note AS 'ملاحظات', input_tb.Worker AS 'اسم المستلم', input_tb.unit1 AS 'الوحدة',input_tb.matter_q AS 'العدد',input_tb.m_type AS 'نوع الفقرة',Matter_tb.matter AS 'الفقرة',input_tb.E_date AS 'التاريخ', input_tb.curr AS 'الوحدة' , input_tb.price AS 'المبلغ' , Place_tb.work_place AS 'اسم الموقع' ,input_tb.ID AS 'رقم الادخال' FROM input_tb INNER JOIN Place_tb ON input_tb.place_no = Place_tb.place_no INNER JOIN Matter_tb ON input_tb.matter_no = Matter_tb.m_no ";

I want to update the data from datagridview which shoe error of the mismatch of data deci=ouse I show the text in datagridview and must put the code of text in this colomun in update

What I have tried:

cmd.CommandText="UPDATE input_tb SET place_no='" + update1.SelectedRows[0].Cells[9].Value + "',price='" + update1.SelectedRows[0].Cells[8] + "',curr='" + update1.SelectedRows[0].Cells[7] + "',E_date='" + update1.SelectedRows[0].Cells[6] + "',m_type='" + update1.SelectedRows[0].Cells[4] + "',matter_q='" + update1.SelectedRows[0].Cells[3] + "',unit1='" + update1.SelectedRows[0].Cells[2] + "',Worker='" + update1.SelectedRows[0].Cells[1] + "',f_note='" + update1.SelectedRows[0].Cells[0] + "' FROM input_tb INNER JOIN Place_tb ON input_tb.place_no = Place_tb.place_no INNER JOIN Matter_tb ON input_tb.matter_no = Matter_tb.m_no WHERE ID=" + update1.SelectedRows[0].Cells["رقم الادخال"].Value;
Posted
Updated 5-May-17 3:00am
Comments
[no name] 5-May-17 8:13am    
Use a proper parameterized query and your problem will likely go away all by itself.

1 solution

Use a parameterized query such as this (untested):
var cmd = new SqlCommand();
cmd.CommandText = "UPDATE input_tb SET place_no=@place,price=@price,curr=@curr,E_date=@E_date,m_type=@m_type,matter_q=@matter_q,unit1=@unit1',Worker=@Worker,f_note=@f_note FROM input_tb INNER JOIN Place_tb ON input_tb.place_no = Place_tb.place_no INNER JOIN Matter_tb ON input_tb.matter_no = Matter_tb.m_no WHERE ID=@ID";
cmd.Parameters.AddWithValue("@place", update1.SelectedRows[0].Cells[9].Value);
cmd.Parameters.AddWithValue("@price", update1.SelectedRows[0].Cells[8].Value);
cmd.Parameters.AddWithValue("@curr", update1.SelectedRows[0].Cells[7].Value);
cmd.Parameters.AddWithValue("@E_date", update1.SelectedRows[0].Cells[6].Value);
cmd.Parameters.AddWithValue("@m_type", update1.SelectedRows[0].Cells[4].Value);
cmd.Parameters.AddWithValue("@matter_q", update1.SelectedRows[0].Cells[3].Value);
cmd.Parameters.AddWithValue("@unit1", update1.SelectedRows[0].Cells[2].Value);
cmd.Parameters.AddWithValue("@Worker", update1.SelectedRows[0].Cells[1].Value);
cmd.Parameters.AddWithValue("@f_note", update1.SelectedRows[0].Cells[0].Value);
cmd.Parameters.AddWithValue("@ID", update1.SelectedRows[0].Cells["رقم الادخال"].Value);

The first thing I notice is that you did not use Cells[5] - only you can tell if that is correct.

Using parameters like this will probably solve your problem as the Parameters will assume the correct type.
 
Share this answer
 

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