Click here to Skip to main content
15,882,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,
I have made a registration form and i have connected it to the database as follows:-
C#
protected void Button9_Click(object sender, EventArgs e)
    {
        String facilities="";
        String recuritementof="";
        String intrvwmode1="",intrvwmode2="",intrvwmode3="",intrvwmode4="";
        String cintletter="";
        String pneeded="";
        
        SqlConnection conn = new SqlConnection();
        SqlCommand comm = new SqlCommand();
        conn.ConnectionString = ConfigurationManager.ConnectionStrings["abc"].ToString();
        comm.Connection = conn;
        comm.CommandType = CommandType.Text;
        comm.Parameters.Add(new SqlParameter("@rname",TextBox8.Text));
        comm.Parameters.Add(new SqlParameter("@cname",TextBox9.Text));
        comm.Parameters.Add(new SqlParameter("@country", TextBox10.Text));
        comm.Parameters.Add(new SqlParameter("@state", TextBox11.Text));
        comm.Parameters.Add(new SqlParameter("@city", TextBox12.Text));
        comm.Parameters.Add(new SqlParameter("@craddress", TextBox13.Text));
        comm.Parameters.Add(new SqlParameter("@paddress", TextBox14.Text));
        comm.Parameters.Add(new SqlParameter("@hremail", TextBox15.Text));
        comm.Parameters.Add(new SqlParameter("@cphone", TextBox16.Text));
        comm.Parameters.Add(new SqlParameter("@hrphone", TextBox17.Text));
        comm.Parameters.Add(new SqlParameter("@faxnum", TextBox18.Text));
        comm.Parameters.Add(new SqlParameter("@pincode", TextBox19.Text));
        comm.Parameters.Add(new SqlParameter("@caddress", TextBox20.Text));
        comm.Parameters.Add(new SqlParameter("@cstartingdate", TextBox21.Text));
        comm.Parameters.Add(new SqlParameter("@dealsin", TextBox22.Text));
        comm.Parameters.Add(new SqlParameter("@recuritementfor", DropDownList5.SelectedItem.ToString()));
        if(RadioButton6.Checked)
        {
            recuritementof="Male";
        }
        else
        {
            recuritementof="Female";
        }
        comm.Parameters.Add(new SqlParameter("@recuritementof",recuritementof));
        comm.Parameters.Add(new SqlParameter("@numofcandidates", TextBox23.Text));
        comm.Parameters.Add(new SqlParameter("@exprequired", DropDownList6.SelectedItem.ToString()));
        comm.Parameters.Add(new SqlParameter("@qualification", DropDownList11.SelectedItem.ToString()));
        comm.Parameters.Add(new SqlParameter("@reliability", TextBox25.Text));
        comm.Parameters.Add(new SqlParameter("@ctc", TextBox26.Text));
        if(RadioButton8.Checked)
        {
            facilities="TA";
        }
        else if(RadioButton9.Checked)
        {
            facilities="DA";
        }
        else if(RadioButton10.Checked)
        {
            facilities="HRA";
        }
        else
        {
            facilities="Medical Support";
        }
        comm.Parameters.Add(new SqlParameter("@facilities", facilities));
        comm.Parameters.Add(new SqlParameter("@candidateemail", TextBox27.Text));
        comm.Parameters.Add(new SqlParameter("@candidatephone", TextBox28.Text));
        comm.Parameters.Add(new SqlParameter("@aboutcmpny", TextBox29.Text));
        comm.Parameters.Add(new SqlParameter("@jobopeningdate", TextBox30.Text));
        comm.Parameters.Add(new SqlParameter("@jobclosingdate", TextBox31.Text));
        if (RadioButton12.Checked)
        {
            intrvwmode1 = "Telephonic";
        }
        else
        {
            intrvwmode1 = "Aptitude Test";
        }
        if (RadioButton14.Checked)
        {
            intrvwmode2 = "GD";
        }
        else
        {
            intrvwmode2 = "Technical Test";
        }
        if (RadioButton16.Checked)
        {
            intrvwmode3 = "Personal Interview";
        }
        else
        {
            intrvwmode3 = "Account Checking";
        }
        if (RadioButton18.Checked)
        {
            intrvwmode4 = "Giving Offer Letter";
        }
        comm.Parameters.Add(new SqlParameter("@interviewmode", intrvwmode1 + intrvwmode2 + intrvwmode3 + intrvwmode4));
        comm.Parameters.Add(new SqlParameter("@venue", TextBox32.Text));
        comm.Parameters.Add(new SqlParameter("@reachat",TextBox33.Text));
        if(RadioButton19.Checked)
        {
            cintletter="Yes";
        }
        else
        {
            cintletter="No";
        }
        comm.Parameters.Add(new SqlParameter("@carryletter", cintletter));
        comm.Parameters.Add(new SqlParameter("@industry", DropDownList7.SelectedItem.ToString()));
        comm.Parameters.Add(new SqlParameter("@rolepost", DropDownList12.SelectedItem.ToString()));
        comm.Parameters.Add(new SqlParameter("@howknow", DropDownList8.SelectedItem.ToString()));
        if(RadioButton3.Checked)
        {
            pneeded="Platinum";
        }
        else if(RadioButton4.Checked)
        {
            pneeded="Gold";
        }
        else
        {
            pneeded="Silver";
        }
        comm.Parameters.Add(new SqlParameter("@planneed", pneeded));
        comm.Parameters.Add(new SqlParameter("@charges", DropDownList9.SelectedItem.ToString()));
        comm.Parameters.Add(new SqlParameter("@paymentmode",DropDownList10.SelectedItem.ToString()));
        comm.CommandText = "insert into recuriter values(@rname,@cname,@country,@state,@city,@craddress,@paddress,@hremail,@cphone,@hrphone,@faxnum,@pincode,@caddress,@cstartingdate,@dealsin,@recuritementfor,@recuritementof,@numofcandidates,@candidatephone,@exprequired,@qualification,@ctc,@facilities,@candidateemail,@candidatephone,@aboutcmpny,@jobopeningdate,@jobclosingdate,@interviewmode,@venue,@reachat,@carryletter,@industry,@rolepost,@howknow,@planneed,@charges,@paymentmode)";
        conn.Open();
        comm.ExecuteNonQuery();
        conn.Close();
        comm.Parameters.Clear();
    }


but when i click at the submit button than it does nothing an its running properly no error is giving. Now i am unable to understand that why the values are not going in to the database.
sir please give me any possible solution.


Thank You.
Posted
Updated 30-Apr-11 22:34pm
v2
Comments
DaveAuld 1-May-11 4:35am    
EDIT: added code formatting
Wonde Tadesse 1-May-11 12:23pm    
Are all the table column datatypes string type(i.e nvarchar, varchar, ntext ...) ?

Your INSERT statement does not list the columns the data is to go into:
SQL
INSERT INTO myTable VALUES (@C1, @C2)
Try:
SQL
INSERT INTO myTable (myColumn1, myColumn2) VALUES (@C1, @C2)

I would expect this to raise an SQL error, but it may be that you are catching the exception and discarding it at a higher level.
 
Share this answer
 
Comments
Shristi Tyagi 1-May-11 5:04am    
Sir i have just tried your solution but my problem is remain same it is doing nothing.
OriginalGriff 1-May-11 5:12am    
Add a try-catch block around your method, and see if you get an error message - you need information as to what is happening at the moment.
Shristi Tyagi 1-May-11 5:18am    
ok sir iam trying.
Shristi Tyagi 1-May-11 5:26am    
sir no effect.i dn't know what to do.
OriginalGriff 1-May-11 5:40am    
OK, so either your code is not executing, or you aren't debugging it.
Have you tried breakpointing it with the debugger? Does it enter the method and stop, waiting for you to continue?
If the debugger doesn't appear to be working for some reason, then try adding tracing statements.
At the top of your method:
StreamWriter sw = File.AppendText(@"F:\Temp\mylog.txt");
sw.WriteLine(DateTime.Now.ToString() + " : Click started.");
At the bottom:
sw.WriteLine(DateTime.Now.ToString() + " : Click ended!");
sw.Close();
In between, you can add bits to check what you are adding, etc.
Put a WriteLine in the catch block to give you any message.

You will want to replace "F:\Temp\" with somewhere you can find easily! Run your program, and see what you get in the text file.

"insert into recuriter (fieldname1,fieldname2,fieldname3)values(@rname,@cname,@country,@state.....

try with it
 
Share this answer
 
at insert statement give as
insert into tablename(col1,col2,....) values(v1,v2...) and put breakpoint cmd.commandText and test it sql server window .
 
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