get a msg that "ID ALREADY EXIST"

Discussion in 'ASP' started by ranchani, Feb 23, 2011.

  1. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    i am a beginner, i don't how to give command

    how to display a msgbox that " ID already exist " for a given textbox

    should i use getfocus if so how????? or is there another way???????/
     
  2. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
     
  3. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    1. Please try and edit your previous post rather than...Just posting a new one..
    2. use the quote tags properly..
    3. Please clear you question...You want a alert box or a simple error text...
     
  4. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    anything is fine as long as it works
     
  5. lionaneesh

    lionaneesh Active Member

    Joined:
    Mar 21, 2010
    Messages:
    848
    Likes Received:
    224
    Trophy Points:
    43
    Occupation:
    Student
    Location:
    India
    In VB because i can make it in javascript if you are OK with it!!
     
  6. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    no i want only in vb
     
  7. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    Hi,
    You can use MsgBox function,have you tried that ?
     
    shabbir likes this.
  8. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    yeah but i not sure where to give the statement and i hav tried everything
     
  9. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    If you are not sure where to give the statement then can you show us your code?
    Sorry to say, if you had tried everything you would have solved that problem.I do'nt think that you have tried everything.
     
  10. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Code:
    Imports System.Data
    Imports System.Data.OleDb
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack = True Then
                Reset()
            End If
        End Sub
    
    
    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
    
            Dim con As New OleDbConnection
            Dim com As New OleDbCommand
            Dim sqlString, STID, STNAME, AGE, ADMNO, FNAME, MNAME, BATCH, ADDRESS, PHNO, MOBNO, EMAIL As String
    
            STID = TextBox1.Text
            STNAME = TextBox2.Text
            AGE = TextBox3.Text
            ADMNO = TextBox4.Text
            FNAME = TextBox5.Text
            MNAME = TextBox6.Text
            BATCH = TextBox7.Text
            ADDRESS = TextBox8.Text
            PHNO = TextBox9.Text
            MOBNO = TextBox10.Text
            EMAIL = TextBox13.Text
    
    
            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Varsha\My music\Visual Studio 2005\WebSites\PSA\App_Data\student.mdb")
            con.Open()
            sqlString = "insert into Table1 values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox13.Text & "')"
            com = New OleDbCommand(sqlString, con)
            com.ExecuteNonQuery()
            MsgBox("Data is successfully entered")
            con.Close()
    
    
        End Sub
     
    Last edited by a moderator: Feb 27, 2011
  11. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    Code:
    Imports System.Data
    Imports System.Data.OleDb
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Dim con As OleDbConnection  'Only need to create OleDbConnection type reference
        Dim com As OleDbCommand     'Only need to create OleDbCommand type reference
        
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack = True Then
                Reset()
            End If
        End Sub
    
    
        Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
    
           
            Dim sqlString, STID, STNAME, AGE, ADMNO, FNAME, MNAME, BATCH, ADDRESS, PHNO, MOBNO, EMAIL As String
    
            STID = TextBox1.Text
            STNAME = TextBox2.Text
            AGE = TextBox3.Text
            ADMNO = TextBox4.Text
            FNAME = TextBox5.Text
            MNAME = TextBox6.Text
            BATCH = TextBox7.Text
            ADDRESS = TextBox8.Text
            PHNO = TextBox9.Text
            MOBNO = TextBox10.Text
            EMAIL = TextBox13.Text
    
    
            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Varsha\My music\Visual Studio 2005\WebSites\PSA\App_Data\student.mdb")
            con.Open()
            sqlString = "insert into Table1 values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "','" & TextBox10.Text & "','" & TextBox13.Text & "')"
            com = New OleDbCommand(sqlString, con)
            com.ExecuteNonQuery()
            MsgBox("Data is successfully entered")
            con.Close()
    
    
        End Sub
        Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Dim checkID As String = "select id_field from table1 where id_field='" + TextBox1.Text + "'"
            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Varsha\My music\Visual Studio 2005\WebSites\PSA\App_Data\student.mdb")
            con.Open()
            com = New OleDbCommand(checkID, con)
            Dim result As SByte = com.ExecuteNonQuery()
            con.Close()
    
            If result > 0 Then
                MsgBox("ID Already Exists!")
                ' Code here to disable submit button
            Else
                'code here to enable submit button
            End If
    
        End Sub
    End Class
    
    Don't hesitate to reply if problem persists.
     
  12. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Dim result As SByte = com.ExecuteNonQuery()

    IM getting this error for that statement

    Data type mismatch in criteria expression.
     
  13. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    oh that was a silly mistake from my side.You can use typecasting:
    Code:
    Dim result As SByte =CType(com.ExecuteNonQuery(),SByte)
    
    or you use directly declare variable of type Integer
    Code:
    Dim result as Integer=com.ExecuteNonQuery()
    
    I suggest you to first grasp the basic things.Then go for such topics.
     
  14. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    no its not working im getting this error "No value given for one or more required parameters."
     
  15. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    Yes, if your database tables's fields do nat match the data you are submitting then you will definitely get such an error.
    Can you post your table's column in.
     
  16. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    <Columns>
    <asp:BoundField DataField="STUDENT_ID" HeaderText="STUDENT_ID" SortExpression="STUDENT_ID" />
    <asp:BoundField DataField="STUDENT_NAME" HeaderText="STUDENT_NAME" SortExpression="STUDENT_NAME" />
    <asp:BoundField DataField="AGE" HeaderText="AGE" SortExpression="AGE" />
    <asp:BoundField DataField="ADMISSION_NUMBER" HeaderText="OCCUPATION" SortExpression="ADMISSION_NUMBER" />
    <asp:BoundField DataField="FATHER_NAME" HeaderText="FATHER_NAME" SortExpression="FATHER_NAME" />
    <asp:BoundField DataField="MOTHER_NAME" HeaderText="MOTHER_NAME" SortExpression="MOTHER_NAME" />
    <asp:BoundField DataField="YEAR_OF_THE_BATCH" HeaderText="YEAR_OF_THE_BATCH" SortExpression="YEAR_OF_THE_BATCH" />
    <asp:BoundField DataField="RESIDENTIAL_ADDRESS" HeaderText="RESIDENTIAL_ADDRESS"
    SortExpression="RESIDENTIAL_ADDRESS" />
    <asp:BoundField DataField="PHONE_NO" HeaderText="PHONE_NO" SortExpression="PHONE_NO" />
    <asp:BoundField DataField="MOBILE_NO" HeaderText="MOBILE_NO" SortExpression="MOBILE_NO" />
    <asp:BoundField DataField="EMAIL_ID" HeaderText="EMAIL_ID" SortExpression="EMAIL_ID" />
    </Columns>
     
  17. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    I am asking about column present in your table(the table on which your insert query is working).
    Please post your table columns with there respective data type.
     
    Last edited: Mar 5, 2011
  18. ranchani

    ranchani New Member

    Joined:
    Jun 25, 2010
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    <asp:Parameter Name="STUDENT_NAME" Type="String" />
    <asp:Parameter Name="AGE" Type="Int32" />
    <asp:Parameter Name="ADMISSION_NUMBER" Type="String" />
    <asp:Parameter Name="FATHER_NAME" Type="String" />
    <asp:Parameter Name="MOTHER_NAME" Type="String" />
    <asp:Parameter Name="YEAR_OF_THE_BATCH" Type="Int32" />
    <asp:Parameter Name="RESIDENTIAL_ADDRESS" Type="String" />
    <asp:Parameter Name="PHONE_NO" Type="Int32" />
    <asp:Parameter Name="MOBILE_NO" Type="Double" />
    <asp:Parameter Name="EMAIL_ID" Type="String" />
    <asp:Parameter Name="STUDENT_ID" Type="Double" />
     
  19. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    Exactly, i was expecting the same.
    Data type mismatch .
    Now this will be your insert query:
    Code:
     sqlString = "insert into Table1 values('" & TextBox1.Text & "'," & TextBox2.Text & ",'" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "'," & TextBox6.Text & ",'" & TextBox7.Text & "'," & TextBox8.Text & "," & TextBox9.Text & ",'" & TextBox10.Text & "'," & TextBox13.Text & ")"
    
    Remember,
    for string datatype use single quotes for the string and for numeric datatype do not use any single quotes.
    Is the issue resolved now ?
     
  20. shyam_oec

    shyam_oec New Member

    Joined:
    Nov 26, 2007
    Messages:
    89
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Software Developer, .NET Framework
    Location:
    Jamshedpur
    Hi,
    may i know your status about this problem ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice