Skip to content

Update my .dmp database by executenonquery but not worked.

daulat singh

daulat singh

Asked Jan 26, 2016, 8:00 AM EST3 answers
Share
LinkedInX
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. 
 
 
 
Java
 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);
            }
        }
 
C#
  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:
 
C#
 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

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    There is no updation on a table .So it returns null value
     
    Please clarify in your table have Id field column .
     
    OUTPUT INSERTED.code where code=" + row["code"] + ""; 
    0
  • daulat singh
    0
    Please clarify in your table have Id field column .
    OUTPUT INSERTED.code where code=" + row["code"] + "";
     
    Yes  in this table has id field but  OUTPUP.INSERTED is not work with this. 
    0
  • 0
    In this case you must check your table data update or not.It return "null" means there is no updation because BoCustomer.id  != tblcustomer.code(there is no data in BOcutomer table corrensponding tblcustomer)
    0