开发者

Update Statement in SQLCommand does not work

I have the following SQLCommand which should do an Update. The issue is, that I get no errors but it still do not update the database?

        SqlConnection sqlconn2 = new SqlConnection(this.connectionString);
        sqlconn2.Open();

        string strCmd = "UPDATE dbo.mydata SET WEB_OBEZ1 = @OBEZ1, WEB_OBEZ2 = @OBEZ2, WEB_OBEZ3 = @OBEZ3 WHERE O_KURZ = @OKURZ";

        using (SqlCommand cmd2 = new SqlCommand(strCmd, sqlconn2))
        {
            cmd2.Parameters.Add("@OBEZ1", SqlDbType.NVarChar);
            cmd2.Parameters.Add("@OBEZ2", SqlDbType.NVarChar);
            cmd2.Parameters.Add("@OBEZ3", SqlDbType.NVarChar);
            cmd2.Parameters.Add("@OKURZ", SqlDbType.NVarChar);


            foreach (DataRow dr in dt.Rows)
            {
                // Felder holen
                string okuerzel = dr["O_KURZ"].ToString();
                string bezeichnung = dr["O_BEZ"].ToString();


                    string[] lines = CreateNewOrgBez(bezeichnung);

                    cmd2.Parameters["@OBEZ1"].Value = lines[0];
                    cmd2.Parameters["@OBEZ2"].Value = lines[1];
                    cmd2.Parameters["@OBEZ3"].Value = lines[2];
                    cmd2.Parameters["@OKURZ"].Value = okuerzel;
                    cmd2.Ex开发者_StackOverflowecuteNonQuery();

            }
        }
        sqlconn2.Close();


Perhaps the length of dt.Rows is zero. have you checked for this?


using transactions? then perhapse a commit is missing?

hth

Mario


Perhapse also the where clause did not match any row in the db?

ExecuteNonQuery() returns the number of rows affected, check it!

hth

Mario

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜