string TLDID = gvTLDs.SelectedRow.Cells[0].Text; always returns 0 in database












1















string TLDID = gvTLDs.SelectedRow.Cells[0].Text;


The code above is always returning 0 in the database. Below is how i am connecting it to the database



SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FatshostsA2ConnectionString"].ConnectionString);
conn.Open();
SqlCommand com = new SqlCommand("INSERT into Interests (TLDID, UserID)" + "values(@TLDID, @UserID)", conn);
com.Parameters.AddWithValue("@TLDID", TLDID);
com.Parameters.AddWithValue("@UserID", Session["User"]);
com.ExecuteNonQuery();
conn.Close();


All of this is executed with the press of a button on my website. I am probably doing something wrong with the way i am calling the value of the cell from the selcted row.










share|improve this question























  • How do you set the value of gvTLDs.SelectedRow.Cells[0].Text ?

    – Chetan Ranpariya
    Jan 1 at 14:31






  • 1





    The instruction com.ExecuteNonQuery(); returns an integer indicating the number of rows changed in the database. When the table in the database has a primary key only one row can contain the value. When you do an INSERT and the key already exists then no row are changed (the integer value will be zero) and you need to do an UPDATE. If you do an UPDATE and the key is not in the database you will also get a zero and then you need to do an INSERT.

    – jdweng
    Jan 1 at 14:37











  • The query is doing an insert into the database. The rest of your code is trying to display a value from a grid. How do these two things relate to eachother? Your question makes no sense.

    – CodingYoshi
    Jan 1 at 15:00
















1















string TLDID = gvTLDs.SelectedRow.Cells[0].Text;


The code above is always returning 0 in the database. Below is how i am connecting it to the database



SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FatshostsA2ConnectionString"].ConnectionString);
conn.Open();
SqlCommand com = new SqlCommand("INSERT into Interests (TLDID, UserID)" + "values(@TLDID, @UserID)", conn);
com.Parameters.AddWithValue("@TLDID", TLDID);
com.Parameters.AddWithValue("@UserID", Session["User"]);
com.ExecuteNonQuery();
conn.Close();


All of this is executed with the press of a button on my website. I am probably doing something wrong with the way i am calling the value of the cell from the selcted row.










share|improve this question























  • How do you set the value of gvTLDs.SelectedRow.Cells[0].Text ?

    – Chetan Ranpariya
    Jan 1 at 14:31






  • 1





    The instruction com.ExecuteNonQuery(); returns an integer indicating the number of rows changed in the database. When the table in the database has a primary key only one row can contain the value. When you do an INSERT and the key already exists then no row are changed (the integer value will be zero) and you need to do an UPDATE. If you do an UPDATE and the key is not in the database you will also get a zero and then you need to do an INSERT.

    – jdweng
    Jan 1 at 14:37











  • The query is doing an insert into the database. The rest of your code is trying to display a value from a grid. How do these two things relate to eachother? Your question makes no sense.

    – CodingYoshi
    Jan 1 at 15:00














1












1








1








string TLDID = gvTLDs.SelectedRow.Cells[0].Text;


The code above is always returning 0 in the database. Below is how i am connecting it to the database



SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FatshostsA2ConnectionString"].ConnectionString);
conn.Open();
SqlCommand com = new SqlCommand("INSERT into Interests (TLDID, UserID)" + "values(@TLDID, @UserID)", conn);
com.Parameters.AddWithValue("@TLDID", TLDID);
com.Parameters.AddWithValue("@UserID", Session["User"]);
com.ExecuteNonQuery();
conn.Close();


All of this is executed with the press of a button on my website. I am probably doing something wrong with the way i am calling the value of the cell from the selcted row.










share|improve this question














string TLDID = gvTLDs.SelectedRow.Cells[0].Text;


The code above is always returning 0 in the database. Below is how i am connecting it to the database



SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["FatshostsA2ConnectionString"].ConnectionString);
conn.Open();
SqlCommand com = new SqlCommand("INSERT into Interests (TLDID, UserID)" + "values(@TLDID, @UserID)", conn);
com.Parameters.AddWithValue("@TLDID", TLDID);
com.Parameters.AddWithValue("@UserID", Session["User"]);
com.ExecuteNonQuery();
conn.Close();


All of this is executed with the press of a button on my website. I am probably doing something wrong with the way i am calling the value of the cell from the selcted row.







c# sql asp.net






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 14:30









Hashim AlshareefHashim Alshareef

213




213













  • How do you set the value of gvTLDs.SelectedRow.Cells[0].Text ?

    – Chetan Ranpariya
    Jan 1 at 14:31






  • 1





    The instruction com.ExecuteNonQuery(); returns an integer indicating the number of rows changed in the database. When the table in the database has a primary key only one row can contain the value. When you do an INSERT and the key already exists then no row are changed (the integer value will be zero) and you need to do an UPDATE. If you do an UPDATE and the key is not in the database you will also get a zero and then you need to do an INSERT.

    – jdweng
    Jan 1 at 14:37











  • The query is doing an insert into the database. The rest of your code is trying to display a value from a grid. How do these two things relate to eachother? Your question makes no sense.

    – CodingYoshi
    Jan 1 at 15:00



















  • How do you set the value of gvTLDs.SelectedRow.Cells[0].Text ?

    – Chetan Ranpariya
    Jan 1 at 14:31






  • 1





    The instruction com.ExecuteNonQuery(); returns an integer indicating the number of rows changed in the database. When the table in the database has a primary key only one row can contain the value. When you do an INSERT and the key already exists then no row are changed (the integer value will be zero) and you need to do an UPDATE. If you do an UPDATE and the key is not in the database you will also get a zero and then you need to do an INSERT.

    – jdweng
    Jan 1 at 14:37











  • The query is doing an insert into the database. The rest of your code is trying to display a value from a grid. How do these two things relate to eachother? Your question makes no sense.

    – CodingYoshi
    Jan 1 at 15:00

















How do you set the value of gvTLDs.SelectedRow.Cells[0].Text ?

– Chetan Ranpariya
Jan 1 at 14:31





How do you set the value of gvTLDs.SelectedRow.Cells[0].Text ?

– Chetan Ranpariya
Jan 1 at 14:31




1




1





The instruction com.ExecuteNonQuery(); returns an integer indicating the number of rows changed in the database. When the table in the database has a primary key only one row can contain the value. When you do an INSERT and the key already exists then no row are changed (the integer value will be zero) and you need to do an UPDATE. If you do an UPDATE and the key is not in the database you will also get a zero and then you need to do an INSERT.

– jdweng
Jan 1 at 14:37





The instruction com.ExecuteNonQuery(); returns an integer indicating the number of rows changed in the database. When the table in the database has a primary key only one row can contain the value. When you do an INSERT and the key already exists then no row are changed (the integer value will be zero) and you need to do an UPDATE. If you do an UPDATE and the key is not in the database you will also get a zero and then you need to do an INSERT.

– jdweng
Jan 1 at 14:37













The query is doing an insert into the database. The rest of your code is trying to display a value from a grid. How do these two things relate to eachother? Your question makes no sense.

– CodingYoshi
Jan 1 at 15:00





The query is doing an insert into the database. The rest of your code is trying to display a value from a grid. How do these two things relate to eachother? Your question makes no sense.

– CodingYoshi
Jan 1 at 15:00












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996284%2fstring-tldid-gvtlds-selectedrow-cells0-text-always-returns-0-in-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996284%2fstring-tldid-gvtlds-selectedrow-cells0-text-always-returns-0-in-database%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith