string TLDID = gvTLDs.SelectedRow.Cells[0].Text; always returns 0 in database
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
add a comment |
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
How do you set the value ofgvTLDs.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
add a comment |
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
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
c# sql asp.net
asked Jan 1 at 14:30
Hashim AlshareefHashim Alshareef
213
213
How do you set the value ofgvTLDs.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
add a comment |
How do you set the value ofgvTLDs.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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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