Must declare the scalar variable “@GenName” [duplicate]
This question already has an answer here:
Error on sql database “Must declare the scalar variable”
2 answers
I am getting this error when trying to run the code below. Any insight on to what I am doing wrong? I am pretty new to this, and want to get this to work pretty bad. I have gotten zero help from this site so far in a previous question I asked. But decided to give this forum another shot, before giving up on stackoverflow
protected void SaveButton_Click(object sender, EventArgs e)
{
SqlConnection myConnection =
new SqlConnection(@"Data Source=.sqlexpress;Initial Catalog=TESTdatabase;Integrated Security=True");
SqlCommand myCommand = new SqlCommand(
"INSERT into tblGenerator (GeneratorName, GeneratorAddress, GeneratorCity, GeneratorState, GeneratorZip, GeneratorPhone, GeneratorContact, GeneratorEPAID)" +
"VALUES (@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID), myConnection");
myCommand.Parameters.AddWithValue("@GeneratorName", GenName.Text);
myCommand.Parameters.AddWithValue("@GeneratorAddress", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GeneratorCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GeneratorState", GenState.Text);
myCommand.Parameters.AddWithValue("@GeneratorZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GeneratorPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GeneratorContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GeneratorEPAID", GenEPAID.Text);
myConnection.Open();
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();
myConnection.Close();
}
c# ado.net sqlconnection
marked as duplicate by GSerg, Uwe Keim
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 19 at 20:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
|
show 1 more comment
This question already has an answer here:
Error on sql database “Must declare the scalar variable”
2 answers
I am getting this error when trying to run the code below. Any insight on to what I am doing wrong? I am pretty new to this, and want to get this to work pretty bad. I have gotten zero help from this site so far in a previous question I asked. But decided to give this forum another shot, before giving up on stackoverflow
protected void SaveButton_Click(object sender, EventArgs e)
{
SqlConnection myConnection =
new SqlConnection(@"Data Source=.sqlexpress;Initial Catalog=TESTdatabase;Integrated Security=True");
SqlCommand myCommand = new SqlCommand(
"INSERT into tblGenerator (GeneratorName, GeneratorAddress, GeneratorCity, GeneratorState, GeneratorZip, GeneratorPhone, GeneratorContact, GeneratorEPAID)" +
"VALUES (@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID), myConnection");
myCommand.Parameters.AddWithValue("@GeneratorName", GenName.Text);
myCommand.Parameters.AddWithValue("@GeneratorAddress", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GeneratorCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GeneratorState", GenState.Text);
myCommand.Parameters.AddWithValue("@GeneratorZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GeneratorPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GeneratorContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GeneratorEPAID", GenEPAID.Text);
myConnection.Open();
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();
myConnection.Close();
}
c# ado.net sqlconnection
marked as duplicate by GSerg, Uwe Keim
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 19 at 20:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
[@GenName] is not the same as [@GeneratorName]
– LarsTech
Jan 19 at 20:54
2
Like your previous question, the connection object does not go inside the double quotes.
– LarsTech
Jan 19 at 20:55
Thank you very much for the response, I was mistaken as to what object I was supposed to put in the quotes, and was using the name of the fields from the sql table.
– Mr.B
Jan 19 at 21:03
@Mr.B LarsTech was talking aboutmyConnection
that you also put inside the query string like in your previous question. You have it highlighted with syntax. You are supposed to call docs.microsoft.com/en-us/dotnet/api/…, you are calling docs.microsoft.com/en-us/dotnet/api/….
– GSerg
Jan 19 at 21:04
Aaaaaha. I see now @GSerg. Thank you for that sir.
– Mr.B
Jan 19 at 21:38
|
show 1 more comment
This question already has an answer here:
Error on sql database “Must declare the scalar variable”
2 answers
I am getting this error when trying to run the code below. Any insight on to what I am doing wrong? I am pretty new to this, and want to get this to work pretty bad. I have gotten zero help from this site so far in a previous question I asked. But decided to give this forum another shot, before giving up on stackoverflow
protected void SaveButton_Click(object sender, EventArgs e)
{
SqlConnection myConnection =
new SqlConnection(@"Data Source=.sqlexpress;Initial Catalog=TESTdatabase;Integrated Security=True");
SqlCommand myCommand = new SqlCommand(
"INSERT into tblGenerator (GeneratorName, GeneratorAddress, GeneratorCity, GeneratorState, GeneratorZip, GeneratorPhone, GeneratorContact, GeneratorEPAID)" +
"VALUES (@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID), myConnection");
myCommand.Parameters.AddWithValue("@GeneratorName", GenName.Text);
myCommand.Parameters.AddWithValue("@GeneratorAddress", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GeneratorCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GeneratorState", GenState.Text);
myCommand.Parameters.AddWithValue("@GeneratorZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GeneratorPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GeneratorContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GeneratorEPAID", GenEPAID.Text);
myConnection.Open();
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();
myConnection.Close();
}
c# ado.net sqlconnection
This question already has an answer here:
Error on sql database “Must declare the scalar variable”
2 answers
I am getting this error when trying to run the code below. Any insight on to what I am doing wrong? I am pretty new to this, and want to get this to work pretty bad. I have gotten zero help from this site so far in a previous question I asked. But decided to give this forum another shot, before giving up on stackoverflow
protected void SaveButton_Click(object sender, EventArgs e)
{
SqlConnection myConnection =
new SqlConnection(@"Data Source=.sqlexpress;Initial Catalog=TESTdatabase;Integrated Security=True");
SqlCommand myCommand = new SqlCommand(
"INSERT into tblGenerator (GeneratorName, GeneratorAddress, GeneratorCity, GeneratorState, GeneratorZip, GeneratorPhone, GeneratorContact, GeneratorEPAID)" +
"VALUES (@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID), myConnection");
myCommand.Parameters.AddWithValue("@GeneratorName", GenName.Text);
myCommand.Parameters.AddWithValue("@GeneratorAddress", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GeneratorCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GeneratorState", GenState.Text);
myCommand.Parameters.AddWithValue("@GeneratorZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GeneratorPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GeneratorContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GeneratorEPAID", GenEPAID.Text);
myConnection.Open();
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();
myConnection.Close();
}
This question already has an answer here:
Error on sql database “Must declare the scalar variable”
2 answers
c# ado.net sqlconnection
c# ado.net sqlconnection
edited Jan 19 at 20:53
Uwe Keim
27.5k31130211
27.5k31130211
asked Jan 19 at 20:45
Mr.BMr.B
54
54
marked as duplicate by GSerg, Uwe Keim
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 19 at 20:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by GSerg, Uwe Keim
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 19 at 20:53
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
[@GenName] is not the same as [@GeneratorName]
– LarsTech
Jan 19 at 20:54
2
Like your previous question, the connection object does not go inside the double quotes.
– LarsTech
Jan 19 at 20:55
Thank you very much for the response, I was mistaken as to what object I was supposed to put in the quotes, and was using the name of the fields from the sql table.
– Mr.B
Jan 19 at 21:03
@Mr.B LarsTech was talking aboutmyConnection
that you also put inside the query string like in your previous question. You have it highlighted with syntax. You are supposed to call docs.microsoft.com/en-us/dotnet/api/…, you are calling docs.microsoft.com/en-us/dotnet/api/….
– GSerg
Jan 19 at 21:04
Aaaaaha. I see now @GSerg. Thank you for that sir.
– Mr.B
Jan 19 at 21:38
|
show 1 more comment
1
[@GenName] is not the same as [@GeneratorName]
– LarsTech
Jan 19 at 20:54
2
Like your previous question, the connection object does not go inside the double quotes.
– LarsTech
Jan 19 at 20:55
Thank you very much for the response, I was mistaken as to what object I was supposed to put in the quotes, and was using the name of the fields from the sql table.
– Mr.B
Jan 19 at 21:03
@Mr.B LarsTech was talking aboutmyConnection
that you also put inside the query string like in your previous question. You have it highlighted with syntax. You are supposed to call docs.microsoft.com/en-us/dotnet/api/…, you are calling docs.microsoft.com/en-us/dotnet/api/….
– GSerg
Jan 19 at 21:04
Aaaaaha. I see now @GSerg. Thank you for that sir.
– Mr.B
Jan 19 at 21:38
1
1
[@GenName] is not the same as [@GeneratorName]
– LarsTech
Jan 19 at 20:54
[@GenName] is not the same as [@GeneratorName]
– LarsTech
Jan 19 at 20:54
2
2
Like your previous question, the connection object does not go inside the double quotes.
– LarsTech
Jan 19 at 20:55
Like your previous question, the connection object does not go inside the double quotes.
– LarsTech
Jan 19 at 20:55
Thank you very much for the response, I was mistaken as to what object I was supposed to put in the quotes, and was using the name of the fields from the sql table.
– Mr.B
Jan 19 at 21:03
Thank you very much for the response, I was mistaken as to what object I was supposed to put in the quotes, and was using the name of the fields from the sql table.
– Mr.B
Jan 19 at 21:03
@Mr.B LarsTech was talking about
myConnection
that you also put inside the query string like in your previous question. You have it highlighted with syntax. You are supposed to call docs.microsoft.com/en-us/dotnet/api/…, you are calling docs.microsoft.com/en-us/dotnet/api/….– GSerg
Jan 19 at 21:04
@Mr.B LarsTech was talking about
myConnection
that you also put inside the query string like in your previous question. You have it highlighted with syntax. You are supposed to call docs.microsoft.com/en-us/dotnet/api/…, you are calling docs.microsoft.com/en-us/dotnet/api/….– GSerg
Jan 19 at 21:04
Aaaaaha. I see now @GSerg. Thank you for that sir.
– Mr.B
Jan 19 at 21:38
Aaaaaha. I see now @GSerg. Thank you for that sir.
– Mr.B
Jan 19 at 21:38
|
show 1 more comment
1 Answer
1
active
oldest
votes
First, Stackoverflow is very helpful :) Don't give up on this platform.
Now for your question:
The parameters your SQL statement is expecting are:
(@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID)
While you later assign them with different names.
It should be:
myCommand.Parameters.AddWithValue("@GenName", GenName.Text);
myCommand.Parameters.AddWithValue("@GenAdd", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GenCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GenState", GenState.Text);
myCommand.Parameters.AddWithValue("@GenZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GenPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GenContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GenEPAID", GenEPAID.Text);
When using @parameter
, you must assign a value to a parameter with the same exact name.
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
You should add a space beforeVALUES ...
, like that: ` VALUES ...`
– SomoKRoceS
Jan 19 at 21:42
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First, Stackoverflow is very helpful :) Don't give up on this platform.
Now for your question:
The parameters your SQL statement is expecting are:
(@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID)
While you later assign them with different names.
It should be:
myCommand.Parameters.AddWithValue("@GenName", GenName.Text);
myCommand.Parameters.AddWithValue("@GenAdd", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GenCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GenState", GenState.Text);
myCommand.Parameters.AddWithValue("@GenZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GenPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GenContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GenEPAID", GenEPAID.Text);
When using @parameter
, you must assign a value to a parameter with the same exact name.
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
You should add a space beforeVALUES ...
, like that: ` VALUES ...`
– SomoKRoceS
Jan 19 at 21:42
add a comment |
First, Stackoverflow is very helpful :) Don't give up on this platform.
Now for your question:
The parameters your SQL statement is expecting are:
(@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID)
While you later assign them with different names.
It should be:
myCommand.Parameters.AddWithValue("@GenName", GenName.Text);
myCommand.Parameters.AddWithValue("@GenAdd", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GenCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GenState", GenState.Text);
myCommand.Parameters.AddWithValue("@GenZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GenPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GenContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GenEPAID", GenEPAID.Text);
When using @parameter
, you must assign a value to a parameter with the same exact name.
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
You should add a space beforeVALUES ...
, like that: ` VALUES ...`
– SomoKRoceS
Jan 19 at 21:42
add a comment |
First, Stackoverflow is very helpful :) Don't give up on this platform.
Now for your question:
The parameters your SQL statement is expecting are:
(@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID)
While you later assign them with different names.
It should be:
myCommand.Parameters.AddWithValue("@GenName", GenName.Text);
myCommand.Parameters.AddWithValue("@GenAdd", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GenCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GenState", GenState.Text);
myCommand.Parameters.AddWithValue("@GenZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GenPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GenContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GenEPAID", GenEPAID.Text);
When using @parameter
, you must assign a value to a parameter with the same exact name.
First, Stackoverflow is very helpful :) Don't give up on this platform.
Now for your question:
The parameters your SQL statement is expecting are:
(@GenName, @GenAdd, @GenCity, @GenState, @GenZip, @GenPhone, @GenContact, @GenEPAID)
While you later assign them with different names.
It should be:
myCommand.Parameters.AddWithValue("@GenName", GenName.Text);
myCommand.Parameters.AddWithValue("@GenAdd", GenAdd.Text);
myCommand.Parameters.AddWithValue("@GenCity", GenCity.Text);
myCommand.Parameters.AddWithValue("@GenState", GenState.Text);
myCommand.Parameters.AddWithValue("@GenZip", GenZip.Text);
myCommand.Parameters.AddWithValue("@GenPhone", GenPhone.Text);
myCommand.Parameters.AddWithValue("@GenContact", GenContact.Text);
myCommand.Parameters.AddWithValue("@GenEPAID", GenEPAID.Text);
When using @parameter
, you must assign a value to a parameter with the same exact name.
answered Jan 19 at 20:48
SomoKRoceSSomoKRoceS
512414
512414
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
You should add a space beforeVALUES ...
, like that: ` VALUES ...`
– SomoKRoceS
Jan 19 at 21:42
add a comment |
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
You should add a space beforeVALUES ...
, like that: ` VALUES ...`
– SomoKRoceS
Jan 19 at 21:42
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
Thank you! I am going to try this immediately.
– Mr.B
Jan 19 at 20:53
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
You're welcome :) let me know if it helped
– SomoKRoceS
Jan 19 at 20:54
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
Well, that got rid of the scalar variable error. But has now thrown an error saying incorrect syntax on myCommand.ExecuteNonQuery()
– Mr.B
Jan 19 at 20:57
You should add a space before
VALUES ...
, like that: ` VALUES ...`– SomoKRoceS
Jan 19 at 21:42
You should add a space before
VALUES ...
, like that: ` VALUES ...`– SomoKRoceS
Jan 19 at 21:42
add a comment |
1
[@GenName] is not the same as [@GeneratorName]
– LarsTech
Jan 19 at 20:54
2
Like your previous question, the connection object does not go inside the double quotes.
– LarsTech
Jan 19 at 20:55
Thank you very much for the response, I was mistaken as to what object I was supposed to put in the quotes, and was using the name of the fields from the sql table.
– Mr.B
Jan 19 at 21:03
@Mr.B LarsTech was talking about
myConnection
that you also put inside the query string like in your previous question. You have it highlighted with syntax. You are supposed to call docs.microsoft.com/en-us/dotnet/api/…, you are calling docs.microsoft.com/en-us/dotnet/api/….– GSerg
Jan 19 at 21:04
Aaaaaha. I see now @GSerg. Thank you for that sir.
– Mr.B
Jan 19 at 21:38