Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have done this to insert data

but i have to do
SQL
insert into regtablename values('" + txtusername.Text + "','" + txtusersurname.Text + "','" + dldbirthdate.SelectedItem.Text + "','" + dldbirthmonth.SelectedItem.Text + "','" + dldbirthyear.SelectedItem.Text + "')";

i have solve it thanks for trying to help me ...

thanks
Gaurang Raval
Posted
Updated 3-Dec-11 12:49pm
v5
Comments
member60 1-Dec-11 5:33am    
what error you are getting ?
[no name] 1-Dec-11 21:08pm    
what is the error message? did you try to debug it?
Gaurangraval 3-Dec-11 13:54pm    
i dont know error now but my problem is hoe to get value from dropdown list but i got the ans it not error of insert qry ...i have to use
'" + dldbirthmonth.SelectedItem.Text + "' then i will get result.

Put a debug point on this line. Run the code.
Once execution stops here, copy the value of this line into management studio and execute the query.
Looking at the error there, you may be able to figure out the cause of it.
 
Share this answer
 
try as
C#
string date= txtusersurname.Text +"/" +dldbirthdate.Text + "/" + dldbirthmonth.Text+ "/"+ dldbirthyear.Text;

 string str="insert into tablename values(@txtusername,@txtusersurname,@date)";
SqlCommand cmd=new SqlCommand(str,connection);
   cmd.Parameters.AddWithValue("txtusername",txtusername.Text);
   cmd.Parameters.AddWithValue("txtuserurname",txtuserurname.Text);
   cmd.Parameters.AddWithValue("date",date);
 
Share this answer
 
Try Your query by specifying the column name like,-

insert into tablename(COLUMN1,COLUMN2,...) VALUES(VALUE1,VALUE2,....)
 
Share this answer
 
How many columns do you have in your table depending on that you need to specify values.

example :

in case of two column table

insert into tablename(col1, col2) values (val1, val2);

you have not specify columns for what you are inserting values. if number of columns are more or less then 3 , your query will be fail.


thanks
-amit.
 
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