数据在Sql Server中存储两次 [英] Data Stored Double Time in Sql Server

查看:90
本文介绍了数据在Sql Server中存储两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





当我保存数据时,它会保存而不会出现任何错误,但保存为空列。



例如:



如果我保存id为2且成功保存但在id no 1(one)之前添加了空列。这里我的代码



DAL:



Hi,

when i save the data it will save without any error but with in that save null columns.

For Example:

if i save id no 2 that saved successfully but before id no 1(one) added empty columns. here my code

DAL:

#region InsertData
   public int Insert(NCBAL ObjInsert)
   {
       con = new SqlConnection(constr);
       con.Open();
       cmd = new SqlCommand("InsertNewComp_SP", con);
       cmd.CommandType = CommandType.StoredProcedure;
       try
       {
           cmd.Parameters.AddWithValue("@compliantID",ObjInsert.compid).ToString();
           cmd.Parameters.AddWithValue("@customerid", ObjInsert.cusid).ToString();
           cmd.Parameters.AddWithValue("@customername", ObjInsert.cusname).ToString();
           cmd.Parameters.AddWithValue("@branchid", ObjInsert.ddlbranch).ToString();
           cmd.Parameters.AddWithValue("@servicetype",ObjInsert.servicetype);
           return cmd.ExecuteNonQuery();
       }
       catch
       {
           throw;
       }
       finally
       {
           cmd.Dispose();
           con.Close();
           con.Dispose();
       }
   }
   #endregion







BAL:






BAL:

#region Insert Data
   public int Insert(NCBAL ObjInsert)
   {
       try
       {
           return ncd.Insert(ObjInsert);
       }
       catch
       {
           throw;
       }
       finally
       {
           ncd = null;
       }
   }
   #endregion







UI:




UI:

ncb.compid = txtcompid.Text;
                        ncb.cusid = txtcusid.Text;
                        ncb.cusname = txtcusname.Text;
                        ncb.cusnum = txtcusnumber.Text;
                        ncb.compname = txtcompname.Text;
                        ncb.ddlproduct = DDlProductname.Text;
                        ncb.compliant = txtCompliant.Text;
                        ncb.compdate = Convert.ToDateTime(txtcompdate.Text);
                        ncb.solution = txtsolution.Text;
                        ncb.ddlassign = DDlAssign.Text;
                        ncb.datetocomp = Convert.ToDateTime(txtdatetocom.Text);
                        ncb.ddlpriorty = DDlPriorty.Text;
                        ncb.ddlstatus = DDlStatus.Text;
                        ncb.complianttime = txtcomplianttime.Text;
                        ncb.datetocomp = txtdatecomptime.Text;
                        ncb.ddlbranch = DDLbranch.Text;
                        String str = "";
                        for (int i = 0; i <= CBLservicetype.Items.Count - 1; i++)
                        {
                            if (CBLservicetype.Items[i].Selected)
                            {
                                if (str == "")
                                {
                                    str = CBLservicetype.Items[i].Text;
                                }
                                else
                                {
                                    str += "," + CBLservicetype.Items[i].Text;
                                }
                            }
                        }
                        ncb.servicetype = str;
                         int result = ncb.Insert(ncb);
                    }



我如何解决这个问题...


How Can i Solve that...

推荐答案

仅回答从未答复的清单:由OP解决。

Answered only to remove from unanswered list: solved by OP.
Thanks for all your valuable suggestion... i got the result...


这篇关于数据在Sql Server中存储两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆