Problem In Coding

Jun 23 2009 10:20 AM
Hi

Actually I Wrote The Code Below for the Datagrid......
>>>


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ComboBoxCoumnGrid
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection conn;
SqlCommand cmd;
SqlDataAdapter sda;
DataTable dt;
SqlCommandBuilder scb;
DataSet ds;
string query;
DataGridViewComboBoxColumn column1;
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection("Data Source=AKSHAY;Initial Catalog=Akshay;Persist Security Info=True;User ID=cosmic; Password=cosmicad1985");
}

private void button2_Click(object sender, EventArgs e)
{
try
{
if (dt != null)
{
dt.Clear();
}
dataGridView1.DataSource = null;
dataGridView1.Rows.Clear();
dataGridView1.Refresh();
query = "select * from emp";
SetData();
conn.Open();
sda.Fill(ds, "emp");
dt = ds.Tables["emp"];
foreach (DataColumn dc in dt.Columns)
{
if (dc.ColumnName.Equals("Dept"))
{
column1 = new DataGridViewComboBoxColumn();
column1.DataPropertyName = dc.ColumnName;
column1.HeaderText = dc.ColumnName;
column1.Name = dc.ColumnName;
column1.SortMode = DataGridViewColumnSortMode.Automatic;
column1.ValueType = dc.DataType;
dataGridView1.Columns.Add(column1);

try
{
SqlCommand cmd1 = new SqlCommand("select dept_name from dept", conn);
SqlDataReader sdr;
sdr = cmd1.ExecuteReader();
while (sdr.Read())
{
column1.Items.Add((string)sdr["dept_name"]);
}
}
catch (Exception ee)
{
MessageBox.Show("Error in retrieving The Product Name values " + ee);
}
break;
}
DataGridViewTextBoxColumn column = new DataGridViewTextBoxColumn();
column.DataPropertyName = dc.ColumnName;
column.HeaderText = dc.ColumnName;
column.Name = dc.ColumnName;
column.SortMode = DataGridViewColumnSortMode.Automatic;
column.ValueType = dc.DataType;
dataGridView1.Columns.Add(column);
}
}
catch (Exception ee)
{
MessageBox.Show("Error in Connection " + ee);
}
finally
{
conn.Close();
}
}
private void SetData()
{
cmd = new SqlCommand(query, conn);
sda = new SqlDataAdapter(cmd);
scb = new SqlCommandBuilder(sda);
ds = new DataSet();
}

private void button1_Click(object sender, EventArgs e)
{
int id;
string pname;

try
{
conn.Open();

for (int i = 0; i <= dataGridView1.Rows.Count; i++)
{
id = (int) dataGridView1.CurrentRow.Cells[0].Value;
pname = dataGridView1.CurrentRow.Cells[1].Value.ToString();
MessageBox.Show("The id Is " + id);
MessageBox.Show("The id Is " + pname);
cmd = new SqlCommand("insert into emp(ecode,ename) values(" + id + ",'" + pname.ToString() + "')",conn);
cmd.ExecuteNonQuery();
//this.dataGridView1.Rows.RemoveAt(this.dataGridView1.CurrentRow.Index);
}
}
catch (Exception ee)
{
MessageBox.Show("Error in Insertion Record " + ee);
}
finally
{
conn.Close();
}
}
}
}


This Code Gave Me Error.........& I was Not Able To Insert record into The Table
---------------------------
 

---------------------------
Error in Insertion Record System.Data.SqlClient.SqlException: INSERT failed because the following SET options have incorrect settings: 'ARITHABORT'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods.

at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)

at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)

at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)

at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)

at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)

at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()

at ComboBoxCoumnGrid.Form1.button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\cosmic\Desktop\ComboBoxCoumnGrid\ComboBoxCoumnGrid\ComboBoxCoumnGrid\Form1.cs:line 117



Please Help Me....


Regards
Akshay

Answers (2)