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
daulat singh
NA
140
3.4k
update my .dmp database by executenonquery but not worked.
Jan 26 2016 1:00 PM
Dear Sir/Me'am,
i have explain my problem with some steps.
1. i have a .dmp (crush dump file) name is db
2. connection is created by oledb like : Provider=Infor.OSOLEDB;Password=Admin;Persist Security Info=True;User ID=Admin;Initial Catalog=LN;Data Source=ERPLN;Location=EXTSCM200912.infor.com
3.db have a table name is BOCustomer.
4.create a table in sql server 2005 : tblCustomer
5 make connection with sql :Data Source=EXTSCM200912.infor.com;Initial Catalog=TestDB;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False; User ID=sa;Password=*****"
6.write a code for update db database table BOCustomer FROM tblCustomer
IF Table
tblCustomer
have
code
against to
BOCustomer
's
id
then it update the Description. of the BOCustomer table.. for more understanding i am
write my code.
DataTable dtsql = new DataTable();
private void fillSql()
{
try
{
SqlConnection conn = Sqlconn();
string QUERY = "select code,Description from tblCustomer";
SqlCommand cmd = new SqlCommand(QUERY, conn);
cmd.CommandType = CommandType.Text;
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
SqlDataAdapter adpt = new SqlDataAdapter(cmd);
adpt.Fill(dtsql);
conn.Close();
if (dt.Rows.Count > 0)
{
cmbSQL.DataSource = dt;
cmbSQL.DisplayMember = "code";
cmbSQL.ValueMember = "Description";
}
else
{
MessageBox.Show("data Does not Exsist");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button6_Click(object sender, EventArgs e)
{
OleDbConnection conn = Oledbconn();
// OleDbTransaction trans = new OleDbTransaction();
// string query = "update BOCustomer set description= '"+dt[]["Description"]+"' where id="+ dt.Rows[0]["code"]+"";
foreach (DataRow row in dtsql.Rows)
{
string query = "update BOCustomer set description= '"+row["Description"]+"' OUTPUT INSERTED.id where id=" + row["code"] + "";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.CommandType = CommandType.Text;
try
{
i=cmd.ExecuteNonQuery();
EXECUTE NON QUERY IS NOT WORKED, DATA IS NOT UPDATE IN BOCUSTOMER TABLE THAT EXIST IN DB.DMP DATABASE -
// CountRow = CountRow + 1;
// MessageBox.Show("Update"+i);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
conn.Close();
MessageBox.Show("Update ");
DvGrid.DataSource = null;
fillgrid();
}
}
IAM FIND ANOTHER ONE SOLUTION : IF I AM REPLACE EXECUTENONQUERY BY EXECUTESCALER THEN IT UPDATE THE DATA BUT DONT RETUN ANY VALUE SO I AM NOT SURE VALUE IS UPDATE OR NOT.
CODE:
private void button6_Click(object sender, EventArgs e)
{
OleDbConnection conn = Oledbconn();
// OleDbTransaction trans = new OleDbTransaction();
// string query = "update BOCustomer set description= '"+dt[]["Description"]+"' where id="+ dt.Rows[0]["code"]+"";
foreach (DataRow row in dtsql.Rows)
{
string query = "update BOCustomer set description= '"+row["Description"]+"' OUTPUT INSERTED.id where id=" + row["code"] + "";
OleDbCommand cmd = new OleDbCommand(query, conn);
cmd.CommandType = CommandType.Text;
try
{
cmd.ExecuteScalar();
// CountRow = CountRow + 1;
// MessageBox.Show("Update"+i);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
conn.Close();
MessageBox.Show("Update ");
DvGrid.DataSource = null;
fillgrid();
}
if i am trying to get value from Execute Scaler.
like :
int32 i=Convert.toint32(cmd.ExecuteScaler);
then given object referances error.
and if i try to :
Object obj=cmd.ExecuteScaler();
then give null referance error.
Please help me.
regrds.
Daulat Singh
[email protected]
Reply
Answers (
3
)
Change DATE FORMAT for selected columns in datagridvew
Regarding Application Error Event