locked
checking for existing data RRS feed

  • Question

  • User1533404450 posted

    I ahve 4tables hd_receiving,hd_spares,dh_Asset,hd_sparecategory

     //Creating receiving_id  and insert it into hd-receiving which is a PK
     DBServices databservice = new DBServices();
    string newRcvID = "SELECT ISNULL(MAX(Receiving_Id),0) + 1 AS max_Id FROM HD_Receiving";
    DataSet ds = databservice.GetDataSet(CommandType.Text, newRcvID, "tblmax");
    ulong Receiving_Id = 0;
    Receiving_Id = Convert.ToUInt64(ds.Tables["tblmax"].Rows[0]["max_Id"]);
    string stgInsertReceiving = "INSERT INTO HD_Receiving(Receiving_Id,Receiving_Date,Received_By,Indent_No) Values( '" + Receiving_Id + "', '" + newRcvdDate + "','" + newRcvdBy + "','" + newindent + "')";
    DataSet dsReceiving = databservice.GetDataSet(CommandType.Text, stgInsertReceiving, "tblRecv");
     
    if (ddlAsset.SelectedIndex != 0 && ddlSpare.SelectedIndex != 0)
     { //when ddlasset and ddlspare both are selected data will b inserted into hd-spares,hd-sparecategory,hd-asset   }

    else if (ddlAsset.SelectedIndex == 0 && ddlSpare.SelectedIndex != 0)
     {//when only ddlspare is select records will b sent in hd-spare and hd-sparecategory   }

    else 
    {//when only ddlasset is selected data will b sent into hd-asset and hd-sparecategory     }


    private void BindData(ulong newReceivingId)
        {
     DBServices dbService = new DBServices();
     string SQLString = "SELECT Serial_No, Model_No,Indent_No, Receiving_Id, Asset_type_Desc,Spare_Desc FROM HD_Spares WHERE (Is_Active = 1)AND Indent_No=('"+ txtIndent.Text +"') UNION SELECT asset_reg_no AS Serial_No, Model_No,Indent_No, Receiving_Id,Asset_Type, Spare_Desc FROM HD_Asset WHERE (Is_Active = 1)AND Indent_No=('"+ txtIndent.Text +"')  ";
    DataSet dsspare = dbService.GetDataSet(CommandType.Text, SQLString, "tblspare");
    gvInventory.DataSource = dsspare.Tables["tblspare"].DefaultView;
    gvInventory.DataBind();
        }

    scenario is that, When i input indent_no it will saved in hd-receiving and den also in other tables.but when existing
    indent_no is again inputed it will not saved in hd-receiving  but saved in all other tables.

    hd-receiving contains
    receiving_id
    indent_no

    Wednesday, August 19, 2009 1:01 AM

Answers

  • User2011918074 posted

    scenario is that, When i input indent_no it will saved in hd-receiving and den also in other tables.but when existing
    indent_no is again inputed it will not saved in hd-receiving  but saved in all other tables.

    Hi Rukhsar123,

    Could you please provide the table structures and some sample data? In T-SQL, I think we can use the EXIST function to determine whether insert new row into the hd-receiving table or not.

    Please refer to the following links for more information:

    Put SQL Server's EXISTS construct to good use
    http://articles.techrepublic.com.com/5100-10878_11-6180272.html

    Using EXISTS
    http://www.sqlteam.com/article/using-exists


    This response contains references to the third party World Wide Web sites. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 24, 2009 4:57 AM