Must declare the scalar variable “@GenName” [duplicate]












-2
















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();
}









share|improve this question















marked as duplicate by GSerg, Uwe Keim c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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 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
















-2
















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();
}









share|improve this question















marked as duplicate by GSerg, Uwe Keim c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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 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














-2












-2








-2









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();
}









share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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 c#
Users with the  c# badge can single-handedly close c# questions as duplicates and reopen them as needed.

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 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














  • 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








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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer
























  • 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 before VALUES ..., like that: ` VALUES ...`

    – SomoKRoceS
    Jan 19 at 21:42




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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.






share|improve this answer
























  • 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 before VALUES ..., like that: ` VALUES ...`

    – SomoKRoceS
    Jan 19 at 21:42


















1














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.






share|improve this answer
























  • 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 before VALUES ..., like that: ` VALUES ...`

    – SomoKRoceS
    Jan 19 at 21:42
















1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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 before VALUES ..., 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











  • 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 before VALUES ..., 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





Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre