Skip to content
Loading
  • Rajeev Punhani
    0
    Hi Bobi,
     
    I think you are getting error near  DropDownList1.Text.Please use SelectedItem.Text or DropDownList1.SelectedValue.If not please post complete error message.
     
    1. DropDownList1.SelectedItem.Text  
     
    0
  • Amit Gupta
    0
    @Bobi
     
    Few things to be consider in this regard
    1. Code must be optimised, as it was poorly written and always complicate the situation to find errors and hard to maintain
     
    You may write the query like
    1. var query  = "insert into tableName (name) values (@name)";  
    2. var command = new SqlCommand(query, connection);  
    3. command.Parameters.AddWithValue("@name", txtName.Text);  
    4.   
    5. // pass connection to command  
    6. command.ExecuteNonQuery ();  
     
    You can insert with or without column name but it should be better to insert it with columnNames.
     
    2. Donot convert DateTime.Now() to dd/mm/yyyy, pass the date time as it is, if still needed use the global format "yyyy-MM-dd"  ( as seen in regDate.Text).
     
    Coming to your question, there might be syntax error in the insert query, just need to put a breakpoint and get the value and paste the value to ssms, you will get the solution there itself.
     
    Hope this helps 
    0
  • Bryian Tan
    0
    You should update the code to wrap the table name ChitFund-CustomerRegistration with brackets [ChitFund-CustomerRegistration]
     
    Further more, once you got everything working, take a look at the Parameterized Query https://msdn.microsoft.com/library/bb738521(v=vs.100).aspx
    0