Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
ExecuteScalar() — Input string error
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Joe Kasedde
9y
555
1
Reply
I am working on a forum for online discussion and after creating a forum and i want users to write articles this is all i get
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 43: cmd.Parameters.Add("@MessageID", System.Data.SqlDbType.Int, 10, "MessageID");
Line 44: cmd.Parameters["@MessageID"].Value = e.Row.Cells[0].Text;
Line 45: string count = (cmd.ExecuteScalar().ToString()); Line causing error
Source File: c:\Users\A\Documents\Visual Studio 2010\WebSites\ODF\Default2.aspx.cs Line: 45
The code is as below
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlConnection CN = new SqlConnection("Data Source=.\\;Initial Catalog=ODF;Integrated Security=True");
CN.Open();
SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM [Comments] WHERE [MessageID] = @MessageID", CN);
cmd.Parameters.Add("@MessageID", System.Data.SqlDbType.Int, 10, "MessageID");
cmd.Parameters["@MessageID"].Value = e.Row.Cells[0].Text; string count = (cmd.ExecuteScalar().ToString());
e.Row.Cells[4].Text = count;
CN.Close();
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Bind data to a DropDownList in Edit & Insert in ListView
How to change the textbox border color when validation fails