Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,


I am developing one inventory software. It an software, hardware and user details entry. Insert and delete operations working properly. Some times There are many entries in same name. So i doing update and delete process are based upon serial number. Before that search the data and display it in gridview.

Update:
From that gridview data will reterive. If there is one entry means click update all the data are passed into insert form. From there the update is performing.
But more there one entry means how can do it?
Update statement is working. It showing data is updated. But data is not updated in database. or it showing syntax error.
See this code please. This is the code i tried,

C#
protected void Button4_Click(object sender, EventArgs e)
    {

        int x;
        String s;
        s = TextBox24.Text;
        x = (Convert.ToInt32(s));
       // cmd = new OleDbCommand("update hardware set hardwarename='"+TextBox2.Text+"', purchasedate='"+TextBox4.Text+"', description='"+TextBox6.Text+"', rate='"+TextBox7.Text+"', deliverydate='"+TextBox8.Text+"', vendarname='"+TextBox39.Text+"', AMC='"+TextBox11.Text+"', firstname='"+TextBox12.Text+"', lastname='"+TextBox31.Text+"', assettag='"+TextBox25.Text+"', processor='"+TextBox27.Text+"', RAM='"+TextBox28.Text+"', harddisk='"+TextBox29.Text+"', DVD='"+TextBox30.Text+"', service tag='"+TextBox32.Text+"' where sno='"+ x +"'", con);
      //  cmd.ExecuteNonQuery();
       

 cmd = new OleDbCommand("UPDATE hardware SET hardwarename=@HW, purchasedate=@PD, description=@DE, rate=@RA, deliverydate=@DD, vendarname=@VN, AMC=@AM, firstname=@FN, lastname=@L, assettag=@AT, processor=@PR, RAM=@RA, harddisk=@HD, DVD=@DVD, serivce tag=@ST WHERE sno=@SN", con);
        cmd.Parameters.AddWithValue("@HW", TextBox2.Text);
        cmd.Parameters.AddWithValue("@PD", TextBox4.Text);
        cmd.Parameters.AddWithValue("@DE", TextBox6.Text);
        cmd.Parameters.AddWithValue("@RA", TextBox7.Text);
        cmd.Parameters.AddWithValue("@DD", TextBox8.Text);
        cmd.Parameters.AddWithValue("@VN", TextBox39.Text);
        cmd.Parameters.AddWithValue("@AM", TextBox11.Text);
        cmd.Parameters.AddWithValue("@FN", TextBox12.Text);
        cmd.Parameters.AddWithValue("@LN", TextBox31.Text);
        cmd.Parameters.AddWithValue("@AT", TextBox25.Text);
        cmd.Parameters.AddWithValue("@PR", TextBox27.Text);
        cmd.Parameters.AddWithValue("@RA", TextBox28.Text);
        cmd.Parameters.AddWithValue("@HD", TextBox29.Text);
        cmd.Parameters.AddWithValue("@DVD", TextBox30.Text);
        cmd.Parameters.AddWithValue("@ST", TextBox32.Text);
        cmd.Parameters.AddWithValue("@SN", x);
        cmd.ExecuteNonQuery();
        Response.Write("<Script>alert('Data has been updated Successfully')</Script>");
    }


Search:

The search option is based on name, department, softwarename in one button option.
Can you say the coding for this option.

I am waiting for your kind reply. Because I need to complete soon.

Thank you,
Posted

cmd.Parameters.AddWithValue("@SN", x); //Remove this one
and Make SN as Primarykey

it its notworking try below

SQL
" SqlConnection con = new SqlConnection(""Data Source=(local);Initial Catalog=LoginDemo;Integrated Security=True"");
        SqlDataAdapter adp = new SqlDataAdapter();
        adp.UpdateCommand = new SqlCommand(""UPDATE CreateUser VALUES(@USERNAME,@PASSWORD) WHERE ID=@ID"",con);
        adp.UpdateCommand.Parameters.Add(""@USERNAME"", SqlDbType.VarChar).Value = TextBox1.Text;
        adp.UpdateCommand.Parameters.Add(""@PASSWORD"", SqlDbType.VarChar).Value = TextBox2.Text;
        con.Open();
        adp.UpdateCommand.ExecuteNonQuery();"
 
Share this answer
 
Did you try to execute the update query on query editor?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900