You must Sign In to post a response.
  • Category: .NET

    How to check and add full stops in the text before inserting into database

    Below is the data that is in open office spread sheet



    ***Header Code Description*** Excel sheet columns
    Add A7694 Some Text under Desription
    Remove From A893421 Some Text under Desription
    Move To M736RV Some Text under Desription
    Delete V43221J Some Text under Desription
    Add G432J8K Some Text under Desription
    Add HY8765G Some Text under Desription
    Add B7654 Some Text under Desription
    Remove From K897655 Some Text under Desription
    Delete RT998766 Some Text under Desription

    Like this i have 9000 rows in excel sheet and 3 columns now what i need is i need to insert the rows which contains Add under Header column,next i need to do the insertion by checking that the code for that particular Add row is not there in database that is directly the code should be checked whether it is there ind database or not and after that i should add a full stop after alphabet and check whether it is there ind database or not,next finally if that code is not there in database then i need to add a full stop for code after 3 digits and then insert into database .Can any one help me out as i am new to this

    Aspx code-

    <asp:FileUpload ID="FileUpload1" runat="server"/>
    <asp:Button ID="Button1" runat="server" Text="ReadFile" OnClick="Button1_Click" />

    C# Code-

    protected void Button1_Click(object sender, EventArgs e)
    {
    try
    {
    // Copy file to app folder
    string fileName = SaveToAppFolder(FileUpload1.PostedFile);

    // Read the File from App folder
    OdsReaderWriter obj = new OdsReaderWriter();
    dset = obj.ReadOdsFile(fileName);
    GridView1.DataSource = dset.Tables[0];
    //DataTable dt = dset.Tables[0];
    GridView1.DataBind();
    Session["DTset"] = dset;
    }
    catch (Exception ex)
    {
    UploadStatusLabel.Text = "Only .ODS Files Are Allowed";
    }
    GridView1.Visible = true;
    }
    string SaveToAppFolder(HttpPostedFile file)
    {

    string savePath = Server.MapPath(".") + "\\TempFiles\\";
    string fileName = FileUpload1.FileName;
    string pathToCheck = savePath + fileName;
    string tempfileName = "";
    if (System.IO.File.Exists(pathToCheck))
    {
    int counter = 2;
    while (System.IO.File.Exists(pathToCheck))
    {

    tempfileName = counter.ToString() + fileName;
    pathToCheck = savePath + tempfileName;
    counter++;
    }

    fileName = tempfileName;
    }
    else
    {

    }
    savePath += fileName;
    FileUpload1.SaveAs(savePath);
    return savePath;

    }

    This is my code to read the spread sheet data how should i perform these three operations before inserting the data in data base they are
    1)only the rows Add should be considered for insertion remaining should be excluded
    2)Check the corresponding Add row Code is already there in database or not,this checking should be done by directly considering the code and by adding full stop after alphabets.
    3)Finally if that code is not there in database then a full stop should be added after three digits for code and then it should be inserted into data base.

    For example-


    Header Code Description
    Move To M736RV Some Text under Desription
    Delete V43221J Some Text under Desription
    Add G432J8 Some Text under Desription
    Add HY8765G Some Text under Desription
    ***only Add should be inserted---->First step
    G432J8K check this code is there in databaase or not after this in this same step add full stop after alphabets and check it is there in data base or not in this way G.432J.8----->second step
    finally add full stop after 3 digits and then insert into database that is G43.2J8***
  • #768491
    Hi,

    We can do those 3 steps, there's no issue about that. But first let me clear some points:

    1. Check G432J8K in db.
    If present then bypass this row.
    If not present then GoTo Step 2.
    2. Check G.432J.8 in db.
    If present then bypass this row.
    If not present then GoTo Step 3.
    3. Insert G43.2J8 in db.

    Suppose all above is done and you are uploading *same spread sheet* 2nd time, then this above always insert G43.2J8 in db. Because you are not checking STEP 3 CODE existence in db.
    Is this your proper requirement? Let us know so that we can provide you best solution.


Sign In to post your comments