TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
PK Singh
NA
165
14.6k
System.Data.SqlClient.SqlException: 'Conversion failed when converting
Mar 8 2021 7:39 AM
i applied many conversion filled but not work please solved it in C#
System.Data.SqlClient.SqlException: 'Conversion failed when converting the nvarchar value 'Ram' to data type int.'
private
void
btnSave_Click(
object
sender, EventArgs e)
{
SqlConnection con =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"mydb"
].ConnectionString);
// con.Open();
int
value;
// foreach (CheckedListBox item in checkedListBox1.Items)
foreach
(DataGridViewRow row
in
dgvFeeHeadName.Rows)
{
for
(
int
i = 0; i < dgvFeeHeadName.Rows.Count; i++)
using
(SqlCommand cmd =
new
SqlCommand(
"INSERT INTO mstFeePlan(ClassID,FeeHeadID,newamount,oldamount) VALUES(@Class,@Name, @Country,@Countrys)"
, con))
{
///cmd.Parameters.AddWithValue("@CustomerId", row.Cells["Id"].Value);
cmd.Parameters.Clear();
//cmd.Parameters.AddWithValue("@Class", Convert.ToInt32( checkedListBox1.Text));
foreach
(
object
item
in
checkedListBox1.CheckedItems)
{
DataRowView rowe = item
as
DataRowView;
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue(
"@Class"
, rowe[
"ClassID"
]);
cmd.Parameters.AddWithValue(
"@Name"
, row.Cells[
"Fee Head"
].Value);
//cmd.Parameters.AddWithValue("@Name", (int)(row.Cells["Fee Head"].Value ?? DBNull.Value));
//cmd.Parameters.AddWithValue("@Name", row.Cells["Fee Head"].Value=Convert.ToInt32(dgvFeeHeadName.Columns["Fee Head"]));
//cmd.Parameters.Add("@Name", SqlDbType.Int).Value = dgvFeeHeadName.Rows[i].Cells["Fee Head"].Value;
cmd.Parameters.AddWithValue(
"@Country"
, Convert.ToInt32(row.Cells[
"New Fees"
].Value));
cmd.Parameters.AddWithValue(
"@Countrys"
, Convert.ToInt32(row.Cells[
"Old Fees"
].Value));
con.Open();
cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
// dgvFeeHeadName.Rows.Clear();
//dgvFeeHeadName.Rows.Clear();
con.Close();
}
}
Reply
Answers (
2
)
How to use TinyMCE.
import data from excel and pass into table