protected void Button3_Click(object sender, EventArgs e)
    {
        String path = Server.MapPath("App_Data\\dnis2010.mdb");
        String sqlQuery = "SELECT * FROM tableRegister WHERE SerialNo=@TextBox41";
        OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + path);
        OleDbCommand aCommand = new OleDbCommand(sqlQuery, aConnection);

        aCommand.Parameters.AddWithValue("TextBox41", TextBox41.Text);

        try
        {
            aConnection.Open();
            OleDbDataReader aReader = aCommand.ExecuteReader();

            if (!aReader.HasRows)
            {
                ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Data Cannot Be Found!');</script>");

                TextBox1.Text = ""; 
                TextBox2.Text = ""; 
                TextBox3.Text = ""; 
                TextBox4.Text = "";
                TextBox5.Text = ""; 
                TextBox6.Text = ""; 
                TextBox40.Text = "";
                TextBox8.Text = ""; 
                TextBox9.Text = "";
                TextBox10.Text = ""; 
                TextBox11.Text = ""; 
                TextBox12.Text = ""; 
                TextBox13.Text = ""; 
                TextBox14.Text = "";
                TextBox15.Text = ""; 
                TextBox16.Text = ""; 
                TextBox17.Text = ""; 
                TextBox18.Text = ""; 
                TextBox19.Text = "";
                TextBox20.Text = ""; 
                TextBox21.Text = ""; 
                TextBox22.Text = ""; 
                TextBox23.Text = ""; 
                TextBox24.Text = "";
                TextBox25.Text = ""; 
                TextBox26.Text = ""; 
                TextBox27.Text = ""; 
                TextBox28.Text = ""; 
                TextBox29.Text = "";
                TextBox31.Text = "";
                TextBox32.Text = ""; 
                TextBox33.Text = ""; 
                TextBox34.Text = ""; 
                TextBox35.Text = "";
                TextBox36.Text = "";
                TextBox37.Text = ""; 
                TextBox38.Text = ""; 
                TextBox39.Text = "";
            }

            else
            {
                while (aReader.Read())
                { 
                    TextBox1.Visible = true; 
                    TextBox2.Visible = true; 
                    TextBox3.Visible = true; 
                    TextBox4.Visible = true;
                    TextBox5.Visible = true;
                    TextBox6.Visible = true; 
                    TextBox40.Visible = true; 
                    TextBox8.Visible = true; 
                    TextBox9.Visible = true; 
                    TextBox10.Visible = true;
                    TextBox11.Visible = true;
                    TextBox12.Visible = true;
                    TextBox13.Visible = true; 
                    TextBox14.Visible = true;
                    TextBox15.Visible = true;
                    TextBox16.Visible = true; 
                    TextBox17.Visible = true;
                    TextBox18.Visible = true;
                    TextBox19.Visible = true;
                    TextBox20.Visible = true;
                    TextBox21.Visible = true;
                    TextBox22.Visible = true;
                    TextBox23.Visible = true; 
                    TextBox24.Visible = true; 
                    TextBox25.Visible = true;
                    TextBox26.Visible = true;
                    TextBox27.Visible = true;
                    TextBox28.Visible = true; 
                    TextBox29.Visible = true;
                    TextBox31.Visible = true;
                    TextBox32.Visible = true; 
                    TextBox33.Visible = true; 
                    TextBox34.Visible = true;
                    TextBox35.Visible = true; 
                    TextBox36.Visible = true;
                    TextBox37.Visible = true; 
                    TextBox38.Visible = true; 
                    TextBox39.Visible = true;
 
                    TextBox1.Text = "StaffName:"; 
                    TextBox2.Text = "StaffID:"; 
                    TextBox3.Text = "Hostname:"; 
                    TextBox4.Text = "Department:"; 
                    TextBox5.Text = "Section:";
                    TextBox6.Text = "Extension:"; 
                    TextBox40.Text = "Type:"; 
                    TextBox8.Text = "IPAddressType:"; 
                    TextBox9.Text = "IPAddress:"; 
                    TextBox10.Text = "MacAddress:";
                    TextBox11.Text = "CPUBrand:"; 
                    TextBox12.Text = "CPUModel:"; 
                    TextBox13.Text = "Processor:"; 
                    TextBox14.Text = "HardDisk:"; 
                    TextBox15.Text = "HDType:";
                    TextBox16.Text = "RAM:"; 
                    TextBox17.Text = "RAMType:";
                    TextBox18.Text = "MonitorBrand:";
                    TextBox19.Text = "MonitorModel:";
                    TextBox20.Text = "SerialNo:";
                    TextBox21.Text = "MouseBrand:"; 
                    TextBox22.Text = "MouseModel:"; 
                    TextBox23.Text = "SerialNo:"; 
                    TextBox24.Text = "KeyboardBrand:"; 
                    TextBox25.Text = "KeyboardModel:";
                    TextBox26.Text = "SerialNo:"; 
                    TextBox27.Text = "CDPlayer:"; 
                    TextBox28.Text = "CDPlayerBrand:"; 
                    TextBox29.Text = "CDPlayerModel:"; 
                    TextBox31.Text = "CDPlayerType:";
                    TextBox32.Text = "Windows:";
                    TextBox33.Text = "Other:"; 
                    TextBox34.Text = "ProductKey:"; 
                    TextBox35.Text = "Microsoft Office:"; 
                    TextBox36.Text = "ProductKey:";
                    TextBox37.Text = "SoftwareName:"; 
                    TextBox38.Text = "LicenceNo:"; 
                    TextBox39.Text = "Remarks:";


                    TextBox1.Text = aReader["StaffName"].ToString();
                    TextBox2.Text = aReader["StaffID"].ToString();
                    TextBox3.Text = aReader["Hostname"].ToString();
                    TextBox4.Text = aReader["Department"].ToString();
                    TextBox5.Text = aReader["Section"].ToString();
                    TextBox6.Text = aReader["Extension"].ToString();
                    TextBox40.Text = aReader["Type"].ToString();
                    TextBox8.Text = aReader["IpAddType"].ToString();
                    TextBox9.Text = aReader["IpAdd"].ToString();
                    TextBox10.Text = aReader["MacAdd"].ToString();
                    TextBox11.Text = aReader["CpuBrand"].ToString();
                    TextBox12.Text = aReader["CpuModel"].ToString();
                    TextBox13.Text = aReader["Processor"].ToString();
                    TextBox14.Text = aReader["HardDisk"].ToString(); 
                    TextBox15.Text = aReader["HDType"].ToString();
                    TextBox16.Text = aReader["RAM"].ToString(); 
                    TextBox17.Text = aReader["RAMType"].ToString();
                    TextBox18.Text = aReader["MonBrand"].ToString();
                    TextBox19.Text = aReader["MonModel"].ToString();
                    TextBox20.Text = aReader["MonSerialNo"].ToString();
                    TextBox21.Text = aReader["MouBrand"].ToString();
                    TextBox22.Text = aReader["MouModel"].ToString(); 
                    TextBox23.Text = aReader["MouSerialNo"].ToString();
                    TextBox24.Text = aReader["KeybBrand"].ToString();
                    TextBox25.Text = aReader["KeybModel"].ToString();
                    TextBox26.Text = aReader["KeybSerialNo"].ToString();
                    TextBox27.Text = aReader["CdPlay"].ToString();
                    TextBox28.Text = aReader["CdPlayBrand"].ToString();
                    TextBox29.Text = aReader["CdPlayModel"].ToString();
                    TextBox31.Text = aReader["CdPlayType"].ToString();
                    TextBox32.Text = aReader["Windows"].ToString();
                    TextBox33.Text = aReader["Other"].ToString();
                    TextBox34.Text = aReader["WProdKey"].ToString();
                    TextBox35.Text = aReader["MS"].ToString();
                    TextBox36.Text = aReader["MSProdKey"].ToString();
                    TextBox37.Text = aReader["SoftwareName"].ToString();
                    TextBox38.Text = aReader["LicenceNo"].ToString();
                    TextBox39.Text = aReader["Remarks"].ToString();
                   
                }
            }
            aReader.Close();
            aConnection.Close();

        }
        catch (Exception) 
        {
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Failed!');</script>"); 
        }
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        String path = Server.MapPath("App_Data\\dnis2010.mdb");
        String sqlQuery = "UPDATE tableRegister SET  StaffName=@TextBox1, StaffID=@TextBox2, [Hostname]=@TextBox3, [Department]=@TextBox4, [Section]=@TextBox5, [Extension]=@TextBox6, Type=@TextBox40, IpAddType=@TextBox8, IpAdd=@TextBox9, MacAdd=@TextBox10, CpuBrand=@TextBox11, CpuModel=@TextBox12, Processor=@TextBox13, HardDisk=@TextBox14, HDType=@TextBox15, RAM=@TextBox16, RAMType=@TextBox17, MonBrand=@TextBox18, MonModel=@TextBox19, MonSerialNo=@TextBox20, MouBrand=@TextBox21, MouModel=@TextBox22, MouSerialNo=@TextBox23, KeybBrand=@TextBox24, KeybModel=@TextBox25, KeybSerialNo=@TextBox26, CdPlay=@TextBox27, CdPlayBrand=@TextBox28, CdPlayModel=@TextBox29, CdPlayType=@TextBox31, Windows=@TextBox32, Other=@TextBox33, WProdKey=@TextBox34, MS=@TextBox35, MSProdKey=@TextBox36, SoftwareName=@TextBox37, LicenceNo=@TextBox38, Remarks=@TextBox39 WHERE SerialNo=@TextBox41"; 
         

        OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + path);
        OleDbCommand aCommand = new OleDbCommand(sqlQuery, aConnection);

        aCommand.Parameters.AddWithValue("TextBox1", TextBox1.Text);
        aCommand.Parameters.AddWithValue("TextBox2", TextBox2.Text);
        aCommand.Parameters.AddWithValue("TextBox3", TextBox3.Text);
        aCommand.Parameters.AddWithValue("TextBox4", TextBox4.Text);
        aCommand.Parameters.AddWithValue("TextBox5", TextBox5.Text);
        aCommand.Parameters.AddWithValue("TextBox6", TextBox6.Text);
        aCommand.Parameters.AddWithValue("TextBox40", TextBox40.Text);
        aCommand.Parameters.AddWithValue("TextBox8", TextBox8.Text);
        aCommand.Parameters.AddWithValue("TextBox9", TextBox9.Text);
        aCommand.Parameters.AddWithValue("TextBox10", TextBox10.Text);
        aCommand.Parameters.AddWithValue("TextBox11", TextBox11.Text);
        aCommand.Parameters.AddWithValue("TextBox12", TextBox12.Text);
        aCommand.Parameters.AddWithValue("TextBox13", TextBox13.Text);
        aCommand.Parameters.AddWithValue("TextBox14", TextBox14.Text);
        aCommand.Parameters.AddWithValue("TextBox15", TextBox15.Text);
        aCommand.Parameters.AddWithValue("TextBox16", TextBox16.Text);
        aCommand.Parameters.AddWithValue("TextBox17", TextBox17.Text);
        aCommand.Parameters.AddWithValue("TextBox18", TextBox18.Text);
        aCommand.Parameters.AddWithValue("TextBox19", TextBox19.Text);
        aCommand.Parameters.AddWithValue("TextBox20", TextBox20.Text);
        aCommand.Parameters.AddWithValue("TextBox21", TextBox21.Text);
        aCommand.Parameters.AddWithValue("TextBox22", TextBox22.Text);
        aCommand.Parameters.AddWithValue("TextBox23", TextBox23.Text);
        aCommand.Parameters.AddWithValue("TextBox24", TextBox24.Text);
        aCommand.Parameters.AddWithValue("TextBox25", TextBox25.Text);
        aCommand.Parameters.AddWithValue("TextBox26", TextBox26.Text);
        aCommand.Parameters.AddWithValue("TextBox27", TextBox27.Text);
        aCommand.Parameters.AddWithValue("TextBox28", TextBox28.Text);
        aCommand.Parameters.AddWithValue("TextBox29", TextBox29.Text);
        aCommand.Parameters.AddWithValue("TextBox31", TextBox31.Text);
        aCommand.Parameters.AddWithValue("TextBox32", TextBox32.Text);
        aCommand.Parameters.AddWithValue("TextBox33", TextBox33.Text);
        aCommand.Parameters.AddWithValue("TextBox34", TextBox34.Text);
        aCommand.Parameters.AddWithValue("TextBox35", TextBox35.Text);
        aCommand.Parameters.AddWithValue("TextBox36", TextBox36.Text);
        aCommand.Parameters.AddWithValue("TextBox37", TextBox37.Text);
        aCommand.Parameters.AddWithValue("TextBox38", TextBox38.Text);
        aCommand.Parameters.AddWithValue("TextBox39", TextBox39.Text);

        try
        {
            aConnection.Open();
            int row = aCommand.ExecuteNonQuery();

            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Record Has Been Updated!');</script>");
            aConnection.Close();
        }

        catch (Exception)
        {
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Fail to Updated!');</script>");
        }
    }

Can anyone correct my coding here..i didn't know what wrong with my code..rely need help coz this is my final project..

First off... MY EYES!!!

Ok, now that I got that out of my system...

Can you please provide an example of what is happening when you run the code? You've provided a very large chunk of code asking us to "correct" it for you but you haven't told us what's going wrong or what it's supposed to achieve.

there's search and update function in my code..the search function is functioning well..the problem is my update function..when i click on update button, the pop-up show failed to update..i want to update the value that i search from my database..

>help..help..help..

Please read the rules before posting again, in particular the 'keep it organized' one - subject titles such as 'help urgent' are not allowed. If you hit 10 infraction points your account gets an automatic ban, so it is worth obeying the rules if you want to continue to benefit from DaniWeb help.


Please show error stack trace. I think some more information is required so that the best course of action can be taken.

ok i'm sorry for my mistake..thnk for reminding me..

I'm not going to claim to be an expert at everything SQL, however, when I write an UPDATE string I do it as follows:

string sqlQuery = "UPDATE tableRegister SET {StaffName,StaffID,Hostname,Department,etc...} VALUES {@TextBox1,@TextBox2,@TextBox3,etc...} WHERE SerialNo=@TextBox41"

I'm not 100% sure that your method using "StaffName=@TextBox1, StaffID=@TextBox2, [Hostname]=@TextBox3" to set the values of the updated components is valid.

Hope this helps :) Please mark as solved if it resolves your issue.

it still come up with failed to updated pop-up..

One thing that would be helpful in determining the nature of the problem here is if you were able to capture the exception that's throwing

catch (Exception)
{
ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Fail to Updated!');</script>");
}

This would at least give us an idea of where the problem is by telling us what error is being generated.

My gut feeling is that it may be related to data types. Are all the columns in your DB varchar variants? or do you have numeric values? or dateTime values, etc?

From what I'm seeing because all of your inputs are being derived as "aCommand.Parameters.AddWithValue" from .Text components of textboxes you're implicitly declaring them all as varchar dataType. That being the case, when you go to update the columns and hit a numeric or Int colum for example, it will throw an error as not being able to convert varchar to numeric from the DB server end.

yes..i'm using MS Access 2010 database..i put all my dataType as Text..even a number..when i put dataType Number the value cannot be save into database..that why i'm declaring all my datatype as Text..can you help me..

SerialNo=@TextBox41 You haven't added the parameter for TextBox41.

This is very bad coding form by the way. Please name your controls, variables and methods so that people who look at your code can tell what it supposed to be happening at a glance.

commented: good catch!! +1
String path = Server.MapPath("App_Data\\dnis2010.mdb");
        String sqlQuery = "INSERT INTO tableRegister (SerialNo,StaffName,StaffID,[Hostname],[Department],[Section],[Extension], Type, IpAddType, IpAdd, MacAdd, CpuBrand, CpuModel, Processor, HardDisk, HDType, RAM, RAMType, MonBrand, MonModel, MonSerialNo, MouBrand, MouModel, MouSerialNo, KeybBrand, KeybModel, KeybSerialNo, CdPlay, CdPlayBrand, CdPlayModel, CdPlayType, Windows, Other, WProdKey, MS, MSProdKey, SoftwareName, LicenceNo, Remarks) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

        OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + path);
        OleDbCommand aCommand = new OleDbCommand(sqlQuery, aConnection);

        aCommand.Parameters.AddWithValue("SerialNo", TextBox7.Text);
        aCommand.Parameters.AddWithValue("StaffName", TextBox1.Text);
        aCommand.Parameters.AddWithValue("StaffID", TextBox2.Text);
        aCommand.Parameters.AddWithValue("[Hostname]", TextBox3.Text);
        aCommand.Parameters.AddWithValue("[Department]", TextBox4.Text);
        aCommand.Parameters.AddWithValue("[Section]", TextBox5.Text);
        aCommand.Parameters.AddWithValue("[Extension]", TextBox6.Text);
        aCommand.Parameters.AddWithValue("Type", TextBox40.Text);
        aCommand.Parameters.AddWithValue("IpAddType", TextBox8.Text);
        aCommand.Parameters.AddWithValue("IpAdd", TextBox9.Text);
        aCommand.Parameters.AddWithValue("MacAdd", TextBox10.Text);
        aCommand.Parameters.AddWithValue("CpuBrand", TextBox11.Text);
        aCommand.Parameters.AddWithValue("CpuModel", TextBox12.Text);
        aCommand.Parameters.AddWithValue("Processor", TextBox13.Text);
        aCommand.Parameters.AddWithValue("HardDisk", TextBox14.Text);
        aCommand.Parameters.AddWithValue("HDType", TextBox15.Text);
        aCommand.Parameters.AddWithValue("RAM", TextBox16.Text);
        aCommand.Parameters.AddWithValue("RAMType", TextBox17.Text);
        aCommand.Parameters.AddWithValue("MonBrand", TextBox18.Text);
        aCommand.Parameters.AddWithValue("MonModel", TextBox19.Text);
        aCommand.Parameters.AddWithValue("MonSerialNo", TextBox20.Text);
        aCommand.Parameters.AddWithValue("MouBrand", TextBox21.Text);
        aCommand.Parameters.AddWithValue("MouModel", TextBox22.Text);
        aCommand.Parameters.AddWithValue("MouSerialNo", TextBox23.Text);
        aCommand.Parameters.AddWithValue("KeybBrand", TextBox24.Text);
        aCommand.Parameters.AddWithValue("KeybModel", TextBox25.Text);
        aCommand.Parameters.AddWithValue("KeybSerialNo", TextBox26.Text);
        aCommand.Parameters.AddWithValue("CdPlay", TextBox27.Text);
        aCommand.Parameters.AddWithValue("CdPlayBrand", TextBox28.Text);
        aCommand.Parameters.AddWithValue("CdPlayModel", TextBox29.Text);
        aCommand.Parameters.AddWithValue("CdPlayType", TextBox31.Text);
        aCommand.Parameters.AddWithValue("Windows", TextBox32.Text);
        aCommand.Parameters.AddWithValue("Other", TextBox33.Text);
        aCommand.Parameters.AddWithValue("WProdKey", TextBox34.Text);
        aCommand.Parameters.AddWithValue("MS", TextBox35.Text);
        aCommand.Parameters.AddWithValue("MSProdKey", TextBox36.Text);
        aCommand.Parameters.AddWithValue("SoftwareName", TextBox37.Text);
        aCommand.Parameters.AddWithValue("LicenceNo", TextBox38.Text);
        aCommand.Parameters.AddWithValue("Remarks", TextBox39.Text);

        try
        {
            aConnection.Open();
            OleDbDataReader aReader = aCommand.ExecuteReader();
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Successfully Insert Into Database!');</script>");

            aReader.Close();
            aConnection.Close();

        }
        catch (Exception)
        {
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Failed to Insert Into Database!');</script>");
        }

this is my insert code..i need to put [] in order to make sure the value of Hostname,Department,Section,Extension can be insert into database..if not the value can't be save into database..

I'm sorry..i'm just a newbie in this field..if i'm wrong please correct me..where should i add the parameter for TextBox41?

Well, you have asked for it to find the row where the serial number is equal to the parameter "TextBox41" but you haven't added the TextBox41 parameter with all the others.

aCommand.Parameters.AddWithValue("TextBox41", TextBox41.Text);

something like this?i fix what u told but still cannot update..

Ok, at least it eliminates that problem.

See your code where you catch(Exception) { /* show your alert*/ } Place a breakpoint on the line that shows the alert. Then, when your program stops, you will be able to hover your mouse over the Exception and it will tell you the error message from the database.

Please copy it here.

sorry i didn't understand what you want me to do..can you explain it further..

catch (Exception)
{
    ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert('Fail to Updated!');</script>");
}

This is an excerpt of the code where you update the database.

You will notice at the top it says catch(Exception) Underneath is your code which shows an alert message.

Place a breakpoint in Visual Studio on the line that you show the alert message and then run your code.

Your program will then PAUSE when it gets to the breakpoint. At this moment, you can then hover your mouse cursor over the Exception class on the first line I copied. This will make a red circle with an exclamation mark in it pop up next to your mouse.

If you click on it, it will expand and show you all the details of the exception that has been caught. One of those will be the Message and another will be the Inner Message.

Please copy them both into a post on the forum.

nothing can be copy..nothing error come up..i don't know how to do it..

So you're saying that you placed a breakpoint on the alert, it popped up the alert but didn't pause your program in Visual Studio?

Which method is being run that is causing your error? What is the method name?

As a side note, I notice you changed the UPDATE string to match the format that I suggested, however... is this the actual string you're using?

String sqlQuery = "INSERT INTO tableRegister (SerialNo,StaffName,StaffID,[Hostname],[Department],[Section],[Extension], Type, IpAddType, IpAdd, MacAdd, CpuBrand, CpuModel, Processor, HardDisk, HDType, RAM, RAMType, MonBrand, MonModel, MonSerialNo, MouBrand, MouModel, MouSerialNo, KeybBrand, KeybModel, KeybSerialNo, CdPlay, CdPlayBrand, CdPlayModel, CdPlayType, Windows, Other, WProdKey, MS, MSProdKey, SoftwareName, LicenceNo, Remarks) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

If it is, then there's a major problem right there, the ?'s need to be replaced with the parameter names you declared and need to be in the same order as the columns are listed in the first part of the INSERT statement. Also, maybe I'm missing something but wasn't this an UPDATE string before and now it's an INSERT? Or are we working with different strings here?

I do have to admit I was mildly mistaken earlier with the formatting as you were correct with

String sqlQuery = "UPDATE tableRegister SET  StaffName=@TextBox1, StaffID=@TextBox2, [Hostname]=@TextBox3, [Department]=@TextBox4, [Section]=@TextBox5, [Extension]=@TextBox6, Type=@TextBox40, IpAddType=@TextBox8, IpAdd=@TextBox9, MacAdd=@TextBox10, CpuBrand=@TextBox11, CpuModel=@TextBox12, Processor=@TextBox13, HardDisk=@TextBox14, HDType=@TextBox15, RAM=@TextBox16, RAMType=@TextBox17, MonBrand=@TextBox18, MonModel=@TextBox19, MonSerialNo=@TextBox20, MouBrand=@TextBox21, MouModel=@TextBox22, MouSerialNo=@TextBox23, KeybBrand=@TextBox24, KeybModel=@TextBox25, KeybSerialNo=@TextBox26, CdPlay=@TextBox27, CdPlayBrand=@TextBox28, CdPlayModel=@TextBox29, CdPlayType=@TextBox31, Windows=@TextBox32, Other=@TextBox33, WProdKey=@TextBox34, MS=@TextBox35, MSProdKey=@TextBox36, SoftwareName=@TextBox37, LicenceNo=@TextBox38, Remarks=@TextBox39 WHERE SerialNo=@TextBox41";

The only thing missing in that was (as mentioned by someone else) that @TextBox41 was not defined in your list of "aCommand.Parameters.AddWithValue".

However, if you are now performing as an INSERT instead of an UPDATE then the format I provided earlier is correct (minus the WHERE clause) for inserting new values into the DB assuming that you correct your ?'s to @TextBox1,@TextBox2,etc...

And by the way, I also agree with the other poster in that all variables and such should be properly named to make it easier to debug and troubleshoot both for yourself and others.

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;

public partial class Update : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        String path = Server.MapPath("App_Data\\dnis2010.mdb");
        String sqlQuery = "SELECT * FROM tableRegister WHERE SerialNo=@TextBox41";
        OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + path);
        OleDbCommand aCommand = new OleDbCommand(sqlQuery, aConnection);

        aCommand.Parameters.AddWithValue("TextBox41", TextBox41.Text);

        try
        {
            aConnection.Open();
            OleDbDataReader aReader = aCommand.ExecuteReader();

            if (!aReader.HasRows)
            {
                ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Data Cannot Be Found!');</script>");

                TextBox1.Text = ""; 
                TextBox2.Text = ""; 
                TextBox3.Text = ""; 
                TextBox4.Text = "";
                TextBox5.Text = ""; 
                TextBox6.Text = ""; 
                TextBox40.Text = "";
                TextBox8.Text = ""; 
                TextBox9.Text = "";
                TextBox10.Text = ""; 
                TextBox11.Text = ""; 
                TextBox12.Text = ""; 
                TextBox13.Text = ""; 
                TextBox14.Text = "";
                TextBox15.Text = ""; 
                TextBox16.Text = ""; 
                TextBox17.Text = ""; 
                TextBox18.Text = ""; 
                TextBox19.Text = "";
                TextBox20.Text = ""; 
                TextBox21.Text = ""; 
                TextBox22.Text = ""; 
                TextBox23.Text = ""; 
                TextBox24.Text = "";
                TextBox25.Text = ""; 
                TextBox26.Text = ""; 
                TextBox27.Text = ""; 
                TextBox28.Text = ""; 
                TextBox29.Text = "";
                TextBox31.Text = "";
                TextBox32.Text = ""; 
                TextBox33.Text = ""; 
                TextBox34.Text = ""; 
                TextBox35.Text = "";
                TextBox36.Text = "";
                TextBox37.Text = ""; 
                TextBox38.Text = ""; 
                TextBox39.Text = "";
            }

            else
            {
                while (aReader.Read())
                { 
                    TextBox1.Visible = true; 
                    TextBox2.Visible = true; 
                    TextBox3.Visible = true; 
                    TextBox4.Visible = true;
                    TextBox5.Visible = true;
                    TextBox6.Visible = true; 
                    TextBox40.Visible = true; 
                    TextBox8.Visible = true; 
                    TextBox9.Visible = true; 
                    TextBox10.Visible = true;
                    TextBox11.Visible = true;
                    TextBox12.Visible = true;
                    TextBox13.Visible = true; 
                    TextBox14.Visible = true;
                    TextBox15.Visible = true;
                    TextBox16.Visible = true; 
                    TextBox17.Visible = true;
                    TextBox18.Visible = true;
                    TextBox19.Visible = true;
                    TextBox20.Visible = true;
                    TextBox21.Visible = true;
                    TextBox22.Visible = true;
                    TextBox23.Visible = true; 
                    TextBox24.Visible = true; 
                    TextBox25.Visible = true;
                    TextBox26.Visible = true;
                    TextBox27.Visible = true;
                    TextBox28.Visible = true; 
                    TextBox29.Visible = true;
                    TextBox31.Visible = true;
                    TextBox32.Visible = true; 
                    TextBox33.Visible = true; 
                    TextBox34.Visible = true;
                    TextBox35.Visible = true; 
                    TextBox36.Visible = true;
                    TextBox37.Visible = true; 
                    TextBox38.Visible = true; 
                    TextBox39.Visible = true;
 
                    TextBox1.Text = "StaffName:"; 
                    TextBox2.Text = "StaffID:"; 
                    TextBox3.Text = "Hostname:"; 
                    TextBox4.Text = "Department:"; 
                    TextBox5.Text = "Section:";
                    TextBox6.Text = "Extension:"; 
                    TextBox40.Text = "Type:"; 
                    TextBox8.Text = "IPAddressType:"; 
                    TextBox9.Text = "IPAddress:"; 
                    TextBox10.Text = "MacAddress:";
                    TextBox11.Text = "CPUBrand:"; 
                    TextBox12.Text = "CPUModel:"; 
                    TextBox13.Text = "Processor:"; 
                    TextBox14.Text = "HardDisk:"; 
                    TextBox15.Text = "HDType:";
                    TextBox16.Text = "RAM:"; 
                    TextBox17.Text = "RAMType:";
                    TextBox18.Text = "MonitorBrand:";
                    TextBox19.Text = "MonitorModel:";
                    TextBox20.Text = "SerialNo:";
                    TextBox21.Text = "MouseBrand:"; 
                    TextBox22.Text = "MouseModel:"; 
                    TextBox23.Text = "SerialNo:"; 
                    TextBox24.Text = "KeyboardBrand:"; 
                    TextBox25.Text = "KeyboardModel:";
                    TextBox26.Text = "SerialNo:"; 
                    TextBox27.Text = "CDPlayer:"; 
                    TextBox28.Text = "CDPlayerBrand:"; 
                    TextBox29.Text = "CDPlayerModel:"; 
                    TextBox31.Text = "CDPlayerType:";
                    TextBox32.Text = "Windows:";
                    TextBox33.Text = "Other:"; 
                    TextBox34.Text = "ProductKey:"; 
                    TextBox35.Text = "Microsoft Office:"; 
                    TextBox36.Text = "ProductKey:";
                    TextBox37.Text = "SoftwareName:"; 
                    TextBox38.Text = "LicenceNo:"; 
                    TextBox39.Text = "Remarks:";


                    TextBox1.Text = aReader["StaffName"].ToString();
                    TextBox2.Text = aReader["StaffID"].ToString();
                    TextBox3.Text = aReader["Hostname"].ToString();
                    TextBox4.Text = aReader["Department"].ToString();
                    TextBox5.Text = aReader["Section"].ToString();
                    TextBox6.Text = aReader["Extension"].ToString();
                    TextBox40.Text = aReader["Type"].ToString();
                    TextBox8.Text = aReader["IpAddType"].ToString();
                    TextBox9.Text = aReader["IpAdd"].ToString();
                    TextBox10.Text = aReader["MacAdd"].ToString();
                    TextBox11.Text = aReader["CpuBrand"].ToString();
                    TextBox12.Text = aReader["CpuModel"].ToString();
                    TextBox13.Text = aReader["Processor"].ToString();
                    TextBox14.Text = aReader["HardDisk"].ToString(); 
                    TextBox15.Text = aReader["HDType"].ToString();
                    TextBox16.Text = aReader["RAM"].ToString(); 
                    TextBox17.Text = aReader["RAMType"].ToString();
                    TextBox18.Text = aReader["MonBrand"].ToString();
                    TextBox19.Text = aReader["MonModel"].ToString();
                    TextBox20.Text = aReader["MonSerialNo"].ToString();
                    TextBox21.Text = aReader["MouBrand"].ToString();
                    TextBox22.Text = aReader["MouModel"].ToString(); 
                    TextBox23.Text = aReader["MouSerialNo"].ToString();
                    TextBox24.Text = aReader["KeybBrand"].ToString();
                    TextBox25.Text = aReader["KeybModel"].ToString();
                    TextBox26.Text = aReader["KeybSerialNo"].ToString();
                    TextBox27.Text = aReader["CdPlay"].ToString();
                    TextBox28.Text = aReader["CdPlayBrand"].ToString();
                    TextBox29.Text = aReader["CdPlayModel"].ToString();
                    TextBox31.Text = aReader["CdPlayType"].ToString();
                    TextBox32.Text = aReader["Windows"].ToString();
                    TextBox33.Text = aReader["Other"].ToString();
                    TextBox34.Text = aReader["WProdKey"].ToString();
                    TextBox35.Text = aReader["MS"].ToString();
                    TextBox36.Text = aReader["MSProdKey"].ToString();
                    TextBox37.Text = aReader["SoftwareName"].ToString();
                    TextBox38.Text = aReader["LicenceNo"].ToString();
                    TextBox39.Text = aReader["Remarks"].ToString();
                   
                }
            }
            aReader.Close();
            aConnection.Close();

        }
        catch (Exception) 
        {
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Failed!');</script>"); 
        }
    }
    protected void Button1_Click1(object sender, EventArgs e)
    {
        String path = Server.MapPath("App_Data\\dnis2010.mdb");
        String sqlQuery = "UPDATE tableRegister SET {StaffName,StaffID,[Hostname],[Department],[Section],[Extension],Type,IpAddType,IpAdd,MacAdd,CpuBrand,CpuModel,Processor,HardDisk,HDType,RAM,RAMType,MonBrand,MonModel,MonSerialNo,MouBrand,MouModel,MouSerialNo,KeybBrand,KeybModel,KeybSerialNo,CdPlay,CdPlayBrand,CdPlayModel,CdPlayType,Windows,Other,WProdKey,MS,MSProdKey,SoftwareName,LicenceNo,Remarks} VALUES {@TextBox1,@TextBox2,@TextBox3,@TextBox4,@TextBox5,@TextBox6,@TextBox40,@TextBox8,@TextBox9,@TextBox10,@TextBox11,@TextBox12,@TextBox13,@TextBox14,@TextBox15,@TextBox16,@TextBox17,@TextBox18,@TextBox19,@TextBox20,@TextBox21,@TextBox22,@TextBox23,@TextBox24,@TextBox25,@TextBox26,@TextBox27,@TextBox28,@TextBox29,@TextBox31,@TextBox32,@TextBox33,@TextBox34,@TextBox35,@TextBox36,@TextBox37,@TextBox38,@TextBox39} WHERE SerialNo=@TextBox41"; 
         

        OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source =" + path);
        OleDbCommand aCommand = new OleDbCommand(sqlQuery, aConnection);

        
        aCommand.Parameters.AddWithValue("TextBox1", TextBox1.Text);
        aCommand.Parameters.AddWithValue("TextBox2", TextBox2.Text);
        aCommand.Parameters.AddWithValue("TextBox3", TextBox3.Text);
        aCommand.Parameters.AddWithValue("TextBox4", TextBox4.Text);
        aCommand.Parameters.AddWithValue("TextBox5", TextBox5.Text);
        aCommand.Parameters.AddWithValue("TextBox6", TextBox6.Text);
        aCommand.Parameters.AddWithValue("TextBox40", TextBox40.Text);
        aCommand.Parameters.AddWithValue("TextBox8", TextBox8.Text);
        aCommand.Parameters.AddWithValue("TextBox9", TextBox9.Text);
        aCommand.Parameters.AddWithValue("TextBox10", TextBox10.Text);
        aCommand.Parameters.AddWithValue("TextBox11", TextBox11.Text);
        aCommand.Parameters.AddWithValue("TextBox12", TextBox12.Text);
        aCommand.Parameters.AddWithValue("TextBox13", TextBox13.Text);
        aCommand.Parameters.AddWithValue("TextBox14", TextBox14.Text);
        aCommand.Parameters.AddWithValue("TextBox15", TextBox15.Text);
        aCommand.Parameters.AddWithValue("TextBox16", TextBox16.Text);
        aCommand.Parameters.AddWithValue("TextBox17", TextBox17.Text);
        aCommand.Parameters.AddWithValue("TextBox18", TextBox18.Text);
        aCommand.Parameters.AddWithValue("TextBox19", TextBox19.Text);
        aCommand.Parameters.AddWithValue("TextBox20", TextBox20.Text);
        aCommand.Parameters.AddWithValue("TextBox21", TextBox21.Text);
        aCommand.Parameters.AddWithValue("TextBox22", TextBox22.Text);
        aCommand.Parameters.AddWithValue("TextBox23", TextBox23.Text);
        aCommand.Parameters.AddWithValue("TextBox24", TextBox24.Text);
        aCommand.Parameters.AddWithValue("TextBox25", TextBox25.Text);
        aCommand.Parameters.AddWithValue("TextBox26", TextBox26.Text);
        aCommand.Parameters.AddWithValue("TextBox27", TextBox27.Text);
        aCommand.Parameters.AddWithValue("TextBox28", TextBox28.Text);
        aCommand.Parameters.AddWithValue("TextBox29", TextBox29.Text);
        aCommand.Parameters.AddWithValue("TextBox31", TextBox31.Text);
        aCommand.Parameters.AddWithValue("TextBox32", TextBox32.Text);
        aCommand.Parameters.AddWithValue("TextBox33", TextBox33.Text);
        aCommand.Parameters.AddWithValue("TextBox34", TextBox34.Text);
        aCommand.Parameters.AddWithValue("TextBox35", TextBox35.Text);
        aCommand.Parameters.AddWithValue("TextBox36", TextBox36.Text);
        aCommand.Parameters.AddWithValue("TextBox37", TextBox37.Text);
        aCommand.Parameters.AddWithValue("TextBox38", TextBox38.Text);
        aCommand.Parameters.AddWithValue("TextBox39", TextBox39.Text);
        aCommand.Parameters.AddWithValue("TextBox41", TextBox41.Text);

        try
        {
            aConnection.Open();
            int row = aCommand.ExecuteNonQuery();

            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Record Has Been Updated!');</script>");
            aConnection.Close();
        }

        catch (Exception)
        {
            ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert ('Fail to Updated!');</script>");
        }
    }
}

can you understand my code?to be honest with you i'm not understand enough about C# code..and the method that you ask for i also didn't know..can you help me?

Try this, change this segment of your code as below:

catch (Exception e)
      {
      MessageBox.Show(e.ToString());
      //ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert('Fail to Updated!');</script>");
      }

This should bring up a messagebox who's text will state the exception that is being thrown and allow you to copy/paste it for us.

Edit: it's 2am here forgot the .ToString() in the above code.

SqlConnection cn = new SqlConnection();
            cn.ConnectionString = "";
[B]//In above ""  add your database path[/B]
            cn.Open();
            SqlCommand cmd = new SqlCommand("update tableRegister set IpAddType =@IpAddType where SerialNo="+TextBox1.ToString() + "", cn);
            cmd.Parameters.AddWithValue("SerialNo", textBox1.Text);
  int n = cmd.ExecuteNonQuery();
            if (n > 0)
            {
                MessageBox.Show("Record Updated");
            }
            cn.Close();

try this

aCommand.Parameters.AddWithValue("TextBox1", TextBox1.Text);

Inseted of writting the "Textbox" u will have to add ur field name inevery line of code.

in update queary write field name =@field name seperated with (,)

I hope It will work

if you use the format

SqlCommand cmd = new SqlCommand("update tableRegister set IpAddType =@IpAddType where SerialNo="+TextBox1.ToString() + "", cn);

you no longer need to use

cmd.Parameters.AddWithValue("SerialNo", textBox1.Text);

since you are adding the variable directly to the string instead of declaring it as a parameter and using the @parametername to insert it into the string.

However, unless you declare @IpAddType as a parameter this code will not work. Basically you can do it either by declaring all the variables as parameters and adding the parameters with @paramName or you can do it where you use " + TextBox1.Text + " replacing the textbox name with the appropriate textbox name at each variable insert.

Something to note... TextBox1.ToString() will not give you the text value of the textbox, TextBox1.Text will.

catch (Exception e)
{
MessageBox.Show(e.ToString());
//ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert('Fail to Updated!');</script>");
}

i cannot use this..it come up with 2 errors..

I've done everything that u all ask me to do..but still i can't update..anyone can help me..

catch (Exception e)
{
MessageBox.Show(e.ToString());
//ClientScript.RegisterStartupScript(typeof(Page), "PopUpMsg", "<script>alert('Fail to Updated!');</script>");
}

i cannot use this..it come up with 2 errors..

Can you tell us what 2 errors you get when you tried this though?

I understand that you are getting errors but about 90% of what we're trying to accomplish here is to find out which errors you're getting so we can help diagnose this.

1. A local variable named 'e' cannot be declared in this scope because it would give a different meaning to 'e', which is already used in a 'parent or current' scope to denote something else.

2. The name 'MessageBox' does not exist in the current context.

any solution u can help me?i'm really struggling right now..

Ok first off, is this a web application or a windows forms application? Because if MessageBox is not available that tells me that you're not running a windows forms app which means (if this is a web-application, ie: run from browser) you should've posted this in the ASP.Net forum to begin with.

Second, try changing the "e" to err or something but if you don't have MessageBox then you'll have to use an alert or something to show the error text on the screen.

Unfortunately I need to step away for a bit so I don't know when I'll next be able to get back to this thread.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.