0

In ASP.NET, I'm trying to configure a DetailsView control with the insert statement. I run the insert command and I get the error:

"Column 'Address' cannot be null"

My SQL:

INSERT INTO Students (Name, Address,College_Status,Email,Fraternity_Status,Major,Pledge_Class,Ship_ID,Dues_Paid,Service_Hours,Money_Donated,Phone,Shirt_Size,Phone_Carrier,Birthday,Chair_Position,Ritual_Proficiency,Library_Hours)  Values (@Name,@Address,@College_Status,@Email,@Fraternity_Status,@Major,@Pledge_Class,@Ship_ID,@Dues_Paid,@Service_Hours,@Money_Donated,@Phone,@Shirt_Size,@Phone_Carrier,@Birthday,@Chair_Position,@Ritual_Proficiency,@Library_Hours)

Any ideas would be greatly appreciated. I think it's just a simple SQL syntax error. Thanks

4
  • post the parameters also Commented May 11, 2013 at 4:22
  • The issue seems to be that the control just cannot accept a blank value in any textbox here. I guess I will try to use a try/catch block. Commented May 11, 2013 at 4:22
  • Please post your SQL table attributes with its datatype Commented May 11, 2013 at 5:12
  • Thanks, but the logic below fully answered the question. I appreciate your willingness to help. Commented May 11, 2013 at 7:22

3 Answers 3

2

It would appear that you are not entering all of the columns for the Students table. Try doing

INSERT INTO Students (*column names*) VALUES (*values*)

This will make sure that your query works even if you add a new column as well as help you with a quick sanity check to ensure that you have all of the columns required.

EDIT:

Based on your new results, I see the problem. Your SQL is wrong. It should be something like this:

INSERT INTO Students (Name) VALUES (@Name)

You shouldn't be using the column name = parameter name in the value section.

EDIT 2:

For the "Address cannot be null error", you need to check the value you are inserting into Address. It is a non-nullable field in the database and the value you are entering is null. This should have you return an error to the user saying they need an address.

Sign up to request clarification or add additional context in comments.

9 Comments

I have updated the columns. The new error spits out: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',Ritual_Proficiency,Library_Hours) Values (Name=@Name,Address`=@Address' at line 1 "
@Klinetel Is there a reason you are using backticks instead of single quotes? I don't ever recall seeing that while doing SQL
Not anymore, I originally used them for columns with spaces in between (two words).
It probably shouldn't make a difference though.
@Klinetel I have updated my answer based on your newest edit.
|
1

The syntax you have written for insert looks strange to me.

It should be,

Insert into table_name (col1, col2) values (@val_col1, @val_col2)

1 Comment

This is for MySQL. Please look above at my edited columns. Should I just use the @values instead of each column name =@something?
1

seems kinda simple. are you still stuck ? http://sqlfiddle.com/#!2/47ed30/1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.