Click here to Skip to main content
15,889,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
sql = "insert into Tb_SCH_Faculty_Details  ([Faculty_Code], [Faculty_Name], [Mobile_No],[Entered_date],[Active],[Allocated_Hours]) " + " values
('" + txt_Faccode.Text.ToUpper() + "','" + Txt_Facname.Text + "','" + txt_Mobile.Text + "', " + string.Format("{0:dd-MMM-yyyy}", DateTime.Now) + ",'A'," + txt_Hrs.Text + ")";


when i run the above query error shows as follows;


No Value given for one or more required parametres.

shows the above error?

what is the problem in my above insert code.

please help me.
Posted
Updated 14-Mar-13 3:36am
v2
Comments
[no name] 14-Mar-13 10:01am    
If you are simply storing DateTime.Now on your INSERT, why don't you just make that a default value for the column?

1 solution

I believe you need to wrap your date in # characters:

C#
string.Format ( "#{0}#", DateTime.Now.ToString ( "dd-MMM-yyyy" ) )
 
Share this answer
 
Comments
[no name] 14-Mar-13 6:52am    
Thanks, it tried your code it is working fine.

Thank you very much for sending the code.
Richard MacCutchan 14-Mar-13 9:35am    
You are doing this in a very dangerous manner, leaving yourself open to SQL injection (Google it) and the destruction of your database. You should also store DateTime values as DateTime types and not as strings.
Richard C Bishop 14-Mar-13 10:09am    
I concur, very risky.
Richard MacCutchan 14-Mar-13 10:52am    
It is really quite worrying how many people are writing this sort of code.
Richard C Bishop 14-Mar-13 10:55am    
Indeed, I got broke of the habit real quick when I posted a question that had some of that in it.

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