Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
ASP.NET
{
                SqlConnection Con = new SqlConnection("Server=.;" + "database=Registration;"+"integrated Security=true;");
            }
            string Query = "Insert into[FormRegistration] values('1','dawood','Ahmed','Khan','Dubai','454','70','A')";
            SqlCommand sqlCommand = new SqlCommand(Query,Con);
            Con.Open();
            int result = sqlCommand.ExecuteNonQuery();
            Con.Close();
            MessageBox.Show($"{result} rows inserted");
}


What I have tried:

private void btn_Click(object sender, EventArgs e)
        {
            string Error = "";
            if (string.IsNullOrEmpty(txtbox1.Text))
            {
                Error = "Please Enter Valid Id";
            }
            if (string.IsNullOrEmpty(txtbox2.Text))
            {
                Error = "Please Enter Valid First Name";
            }
            if (string.IsNullOrEmpty(txtbox3.Text))
            {
                Error = "Please Enter MiddleName";
            }
            if (string.IsNullOrEmpty(txtbox4.Text))
            {
                Error = "Please Enter  LastName";
            }
            if (string.IsNullOrEmpty(txtbox5.Text))
            {
                Error = "Please Enter Address";
            }
            if (string.IsNullOrEmpty(txtbox6.Text))
            {
                Error = "Please Enter Marks";
            }
            if (string.IsNullOrEmpty(txtbox7.Text))
            {
                Error = "Please Enter Percentage";
            }
            if (string.IsNullOrEmpty(txtbox8.Text))
            {
                Error = "Please Enter Grade";
            }
            if (Error.Length > 0)
            {
                MessageBox.Show(Error, "Validation Error", MessageBoxButtons.YesNo);
            }
            else
            {
                SqlConnection Con = new SqlConnection("Server=.;" + "database=Registration;"+"integrated Security=true;");
            }
            string Query = "Insert into[FormRegista] values('1','dawood','Ahmed','Khan','Dubai','454','70','A')";
            SqlCommand sqlCommand = new SqlCommand(Query,Con);
            Con.Open();
            int result = sqlCommand.ExecuteNonQuery();
            Con.Close();
            MessageBox.Show($"{result} rows inserted
Posted
Updated 14-Mar-22 0:33am
Comments
Richard Deeming 14-Mar-22 6:25am    
You've forgotten to ask a question. You need to explain precisely what the problem is, what you have tried, and where you are stuck. Remember to include the full details of an errors.
vishnu satpathy 14-Mar-22 11:58am    
Well the Moment I enter in sql Connection by giving . name as server name and following other protocol it still giving me .con error
I tried all other thing but it didn't worked anyhow....
As I have given . as server name in my previous exercises that time it worked so don't know where i am making mistake...
CHill60 14-Mar-22 12:31pm    
Give us the precise error message

1 solution

Your connection string needs to name the server - you only have "." e.g. see SQL Server connection strings - ConnectionStrings.com[^]
There is also no need to have the sections as separate strings that are then concatenated. Just create it a single string.

As an aside - give your textboxes meaningful names - don't just leave them with the default names
 
Share this answer
 
Comments
Richard Deeming 14-Mar-22 9:22am    
. is an alias for the default SQL Server instance on the local computer. :)
vishnu satpathy 14-Mar-22 11:53am    
I have tried that too but it isn't working anyway
Richard Deeming 14-Mar-22 11:54am    
As I said, you have forgotten to ask a question. Nobody can help you if you can't describe the problem.
vishnu satpathy 14-Mar-22 12:01pm    
https://meet.google.com/kxh-bnfq-yoe
CHill60 14-Mar-22 12:32pm    
I did not know that! Still learning stuff every day

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