plzz help urgent----default value entering database

Last post 05-16-2008 8:54 AM by che3358. 8 replies.

Sort Posts:

  • plzz help urgent----default value entering database

    05-14-2008, 7:00 AM
    • Loading...
    • tanya2001
    • Joined on 10-15-2007, 12:24 PM
    • Posts 243

    hi all..urgent help needed plzzzz

    Well i have this data to enter into the database using vb.net and sqlserver...i did the coding and it was all working fine until yesterday..i installed in on clients system but now...its taking someother data into it..the ward field is taking a defualt value not the value which is choosen by the user...rest all r working fine except ward field...what should i do..can soebody explain me y did it happen all of a sudden when it was working fine till yesterday...let me explain the code

     Private Sub Submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If TextBox2.Text = "" Or TextBox3.Text = "" Or ComboBox4.Text = "" Or ComboBox3.Text = "" Or ComboBox5.Text = "" Or TextBox1.Text = "" Or ComboBox1.Text = "" Or ComboBox6.Text = "" Then
                MessageBox.Show("Enter all Values")
            Else
                con = New SqlConnection("Server=;uid=sa;pwd=;Database=")
                con.Open()
                Dim param As New SqlParameter()
                param.ParameterName = "@PhoneNumber"
                param.Value = TextBox1.Text + TextBox2.Text
                myCommand = New SqlCommand("Insert into Telecheck(DateCheck,Entryname,Hospital,Ward,PhoneNumber,StaffName,StatusOfStaff,StatusOfPhone)values(getdate(),@Entryname,@Hospital,@Ward,@PhoneNumber,@StaffName,@StatusOfStaff,@StatusOfPhone)", con)
                myCommand.Parameters.Add(New SqlClient.SqlParameter("@Hospital", ComboBox1.SelectedItem.ToString()))
                myCommand.Parameters.Add(New SqlClient.SqlParameter("@Ward", ComboBox3.SelectedValue.ToString()))
                myCommand.Parameters.Add(param)
                'myCommand.Parameters.Add(New SqlClient.SqlParameter("@PhoneNumber", TextBox2.Text))
                myCommand.Parameters.Add(New SqlClient.SqlParameter("@StaffName", TextBox3.Text))
                myCommand.Parameters.Add(New SqlClient.SqlParameter("@Entryname", ComboBox6.Text))
                myCommand.Parameters.Add(New SqlClient.SqlParameter("@StatusOfStaff", ComboBox4.SelectedItem.ToString()))
                myCommand.Parameters.Add(New SqlClient.SqlParameter("@StatusOfPhone", ComboBox2.SelectedItem.ToString()))
                ra = myCommand.ExecuteNonQuery()
                MessageBox.Show("Record entered")
                con.Close()
                ComboBox1.Text = ""
                TextBox1.Text = ""
                ComboBox2.Text = ""
                TextBox2.Text = ""
                TextBox3.Text = ""
                ComboBox6.Text = ""
                ComboBox5.Text = ""
                ComboBox3.Text = ""
                ComboBox4.Text = ""

            End If
        End Sub

    the above is the wy i used to enter ward details into the database but now it is not entering the choosen value of combo box its taking some other defualt value and entering into the database...i dont know why it happened all of a sudden...what could be the problem...now i am taking the values into this combobox like this

     Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            TextBox1.Text = ""
            ComboBox5.Text = ""
            Dim cn As New SqlConnection("Server=;uid=sa;pwd=;Database=")
            cn.Open()
            Dim cmd As SqlCommand = New SqlCommand("select Ward from Wardplans where Hospital='" & ComboBox1.SelectedItem.ToString() & "'", cn)
            Dim ad As SqlDataAdapter = New SqlDataAdapter(cmd)
            Dim t As New DataTable
            ad.Fill(t)
            ComboBox3.BeginUpdate()
            ComboBox3.DataSource = t
            ComboBox3.DisplayMember = "Ward"
            ComboBox3.ValueMember = "Ward"
            ComboBox3.EndUpdate()
            cn.Close()
        End Sub

  • Re: plzz help urgent----default value entering database

    05-14-2008, 8:44 AM
    • Loading...
    • nKognito
    • Joined on 03-06-2008, 5:11 AM
    • Posts 284

    You always confusing between Combo.SelectedValue and Combo.SelectedItem.. Also Combo.SelectedItem.ToString() will not give you value but Combo.SelectedItem.Value will do..

    May the force be with you
  • Re: plzz help urgent----default value entering database

    05-14-2008, 8:52 AM
    • Loading...
    • che3358
    • Joined on 09-25-2003, 10:23 AM
    • Cleveland, OH
    • Posts 845

    Replace the line myCommand.Parameters.Add(New SqlClient.SqlParameter("@Ward", ComboBox3.SelectedValue.ToString()))
     with myCommand.Parameters.Add(New SqlClient.SqlParameter("@Ward", "Test")) to see what happens. If this doesn't work, some thing was wrong with your DB. Otherwise, you have problem with the control ComboBox3. I guess you should check user types some thing in the ComboBox or selects some thing in the control. Also, I noticed that your used SelectedItem for all other ComboBox except the ComboBox3.

    Hope it gives you clues.

  • Re: plzz help urgent----default value entering database

    05-14-2008, 10:06 AM
    • Loading...
    • tanya2001
    • Joined on 10-15-2007, 12:24 PM
    • Posts 243

    hi thanx for the reply...i tried it using "test" and it is inserting  test value in ward column....and also i cannot use selectedItem.value as it shows an error that it is not a valid properly for system.datarow

    and what preoperty of the combox r u talking abt...which one should i change and how was it working for so long...plzz help m new to .net n m using vs.net 2005 

  • Re: plzz help urgent----default value entering database

    05-14-2008, 10:13 AM
    • Loading...
    • che3358
    • Joined on 09-25-2003, 10:23 AM
    • Cleveland, OH
    • Posts 845

    That means the problem comes with your ComboBox2. Try ComboBox2.SelectedItem.ToString(). Be aware that becasue you use ComboBox, it will be possible that user types in text instead of selecting. So, check the reference of the ComboBox to make decision for your coding.

  • Re: plzz help urgent----default value entering database

    05-14-2008, 10:18 AM
    • Loading...
    • tanya2001
    • Joined on 10-15-2007, 12:24 PM
    • Posts 243

    u mean combobox3 right? yes i tried using selecteditem.tostring...its nt working...the only thing wrking is selectedvalue.tostring() which i have used...and what is the reference u r talking abt... 

  • Re: plzz help urgent----default value entering database

    05-14-2008, 10:34 AM
    • Loading...
    • che3358
    • Joined on 09-25-2003, 10:23 AM
    • Cleveland, OH
    • Posts 845

    It seems ComboBox3 is different from other ComboBox that allows selecteditem.tostring from your code. Check the reference to see what else proportites available besides SelectedValue. You need to get the selected items string value or user input text value.

  • Re: plzz help urgent----default value entering database

    05-16-2008, 5:46 AM
    • Loading...
    • tanya2001
    • Joined on 10-15-2007, 12:24 PM
    • Posts 243

    hey there...m still not getting it..what should i do?what could be the problem.....do u need any further code of the project to look further into it... 

  • Re: plzz help urgent----default value entering database

    05-16-2008, 8:54 AM
    Answer
    • Loading...
    • che3358
    • Joined on 09-25-2003, 10:23 AM
    • Cleveland, OH
    • Posts 845

    ComboBox is not a standard .NET web control, so we can't know what are the propertities it has. That was why I suggested you to see the references of the controls. If ComboBox 3 has the same or similar functionality to your ComboBox4 or 5, you can try to use ComboBox4 to replace ComboBox3 so that you can apply SelectedItem propertity.

Page 1 of 1 (9 items)
Microsoft Communities
Page view counter