0
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
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.
0
ranchani's Avatar, Join Date: Jun 2010
Go4Expert Member
Dim result As SByte = com.ExecuteNonQuery()

IM getting this error for that statement

Data type mismatch in criteria expression.
0
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
Quote:
Originally Posted by ranchani View Post
Dim result As SByte = com.ExecuteNonQuery()

IM getting this error for that statement

Data type mismatch in criteria expression.
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.
0
ranchani's Avatar, Join Date: Jun 2010
Go4Expert Member
no its not working im getting this error "No value given for one or more required parameters."
0
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
Quote:
Originally Posted by ranchani View Post
no its not working im getting this error "No value given for one or more required parameters."
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.
0
ranchani's Avatar, Join Date: Jun 2010
Go4Expert Member
<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>
0
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
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 by shyam_oec; 5Mar2011 at 22:23..
0
ranchani's Avatar, Join Date: Jun 2010
Go4Expert Member
<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" />
0
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
Quote:
Originally Posted by ranchani View Post
<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" />
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 ?
0
shyam_oec's Avatar, Join Date: Nov 2007
Contributor
Quote:
Originally Posted by ranchani View Post
how to display a msgbox that " ID already exist " for a given textbox
Hi,
may i know your status about this problem ?