Skip to content Skip to sidebar Skip to footer

Cannot Insert Data Into Database

I just want what my title says.I have already read all the previous similar posts but i couldn't find a solution .Could you please take a watch into my code? EDIT:I don't get any

Solution 1:

You don't seem to be actually executing your query. Execute it before you close your connection.

nonquerycommand.ExecuteNonQuery();

Solution 2:

Two things jump out immediately here.

  1. When you retrieve the connection string from ConfigurationManager.ConnectionStrings you should be passing the name of the connection string in the config file and not the connection string it self. I suspect you might not even be getting a valid connection string.

  2. You need to call ExecuteNonQuery() on the nonqueryCommand instance.

Solution 3:

Instead of

nonqueryCommand.Parameters.Add("@username", SqlDbType.VarChar,20);
nonqueryCommand.Parameters["@username"].Value = UsernameTextbox.Text.ToString();

Use

nonqueryCommand.Parameters.AddWithValue("@username", UsernameTextbox.Text.ToString());

And execute your query:

nonquerycommand.ExecuteNonQuery();

Solution 4:

Chris Farmer has the money.

Add...

nonqueryCommand.ExecuteNonQuery();

Solution 5:

you must assign connection to command before executing query for that add following line before thisConnection.Open();

nonqueryCommand.Connection=thisConnection;

Post a Comment for "Cannot Insert Data Into Database"