none
Regarding data manipulation in asp.net using vb RRS feed

  • Question

  • Hi all,

    I am new to asp.net programming and i am designing a website for HR of my company in asp.net using vb. I have written a code for saving the form values into the database but i am not able to retrieve the database values for modifying the data and saving back those values into the database.

    Actually my requirement is if a user selects a name in the drop down list all the respective fields for that particular employee should me made editable and if the user changes some values then the form should ask for a confirmation message for saving the values and those values should be updated into the database.

    My code for form editing goes here:

    Dim DBConn As New Data.SqlClient.SqlConnection("Data Source=.\sqlexpress;Initial Catalog=HRDATA;Integrated Security=True")
            'Dim DBCmd As New Data.SqlClient.SqlCommand
            Dim DBAdap As New Data.SqlClient.SqlDataAdapter
            Dim DS As New Data.DataSet
            DBConn.Open()
            Dim DBCmd As New Data.SqlClient.SqlCommand("Select Designation,ContactNumber,EmergencyContact,OfficeNumber,Email,PersonalEmail,Dob,Doj,Address,BankName,Branch,AccountNumber,Salary from Employeedata Where ID = 1 ", DBConn)
            Dim dataReader As Data.SqlClient.SqlDataReader
            dataReader = DBCmd.ExecuteReader()
            If (dataReader.Read()) Then
                txtdesig.Text = dataReader("Designation").ToString()
                txtcnum.Text = dataReader("ContactNumber").ToString()
                txtemercont.Text = dataReader("EmergencyContact").ToString()
                txtofficenum.Text = dataReader("OfficeNumber").ToString()
                txtemailid.Text = dataReader("Email").ToString()
                txtpid.Text = dataReader("PersonalEmail").ToString()
                txt_dob.Text = dataReader("Dob").ToString()
                txtdoj.Text = dataReader("Doj").ToString()
                txtaddress.Text = dataReader("Address").ToString()
                txtbankname.Text = dataReader("BankName").ToString()
                txtbranch.Text = dataReader("Branch").ToString()
                txtaccountnum.Text = dataReader("AccountNumber").ToString()
                txtsal.Text = dataReader("Salary").ToString()
            End If
            DBConn.Close()
            dataReader.Close()
        End Sub

    Any help or suggestions are greatly appreciated.

    Thanks in advance,
    Karthik.
    Monday, January 5, 2009 11:23 AM

All replies

  • And what is not working?
    Ewald - Please remember to mark the replies as answers if they help.
    Monday, January 5, 2009 1:35 PM
  • Hi Ewald,

    My problem is i am not able to get the data for the remaining values in the ID instead i am able get the data only for id =1. That is my problem.

    Dim DBCmd As New Data.SqlClient.SqlCommand("Select Designation,ContactNumber,EmergencyContact,OfficeNumber,Email,PersonalEmail,Dob,Doj,Address,BankName,Branch,AccountNumber,Salary from Employeedata Where ID = 1 ", DBConn)
     
    also i need to save back these values that are changed into the database how can we do that please help me i am fresher.

    Thanku for replying,
    Karthik.
    Monday, January 5, 2009 2:03 PM
  • karthik the cool said:

    My problem is i am not able to get the data for the remaining values in the ID instead i am able get the data only for id =1. That is my problem.


    Does the SQL statement return multiple records for the ID = 1? Is that what you mean?



    When you want to write the values back to the database, you have to set the UpdateCommand of the DataAdapter. You can either create your own update statement, or you can use the Commandbuilder to create the update statement.

    Ewald - Please remember to mark the replies as answers if they help.
    Monday, January 5, 2009 7:45 PM
  • Hi Ewald,

    Thanks for ur reply butactually i wanted to display records of different users just by changing the value in the drop downlist for ID. Presently i am able to retrieve only values of Id value = 1 but i have 30 values in the ID ddl and i want to display records for each Id jus by selecting the value in the drop down list.

    Thanks in advance,
    Karthik.


    Tuesday, January 6, 2009 5:31 AM
  • You should make use of parameters. 

            Dim DBCmd As New Data.SqlClient.SqlCommand("Select ... from Employeedata Where ID = @Id", DBConn)
            DBCmd.Parameters.AddWithValue("@Id", CInt(myIdCombo.SelectedValue))

    Ewald - Please remember to mark the replies as answers if they help.
    Tuesday, January 6, 2009 8:56 PM