Question Insert data function not working

7thAkash

New member
Joined
Mar 8, 2010
Messages
2
Programming Experience
Beginner
Sorry guys dont knwo the code tags for the forum
below is the function i am using to insert data in the dataBase

where query is passed as the argument
getDBConnection is a function that returns the sqlConnection object

After inserting msgbox displays ra as "1"

Public Function InsertData(ByVal query As String)

Dim con1 As Data.SqlClient.SqlConnection = getDBConnection()

Dim command As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(query, con1)
Dim ra As Integer
ra = command.ExecuteNonQuery()
MsgBox(ra)
Return 1
End Function

But when i try to get the count of rows rite after the insertion using below funtion i get it as 0 though no errors are thrown while insertion


Below is the function that returns the number of rows in the database
and it always returns 0
even if insert function has been run multiple times :eek:
Public Function getSerial() As Integer

Dim con1 As Data.SqlClient.SqlConnection = getDBConnection()
Dim query As String
query = "select count(*) from PersonalDetails"

Dim command As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(query, con1)
Dim dataReader As Data.SqlClient.SqlDataReader
Dim serial As Integer
dataReader = command.ExecuteReader
If dataReader.Read Then
serial = dataReader(0)
End If
dataReader.Close()
Return serial
End Function


any idea why this is not working?
its a form based app
 
Thanks John

Guys any idea why the below code is not working
below is the function i am using to insert data in the dataBase

where query is passed as the argument
getDBConnection is a function that returns the sqlConnection object

After inserting msgbox displays ra as "1"

VB.NET:
Public Function InsertData(ByVal query As String)

Dim con1 As Data.SqlClient.SqlConnection = getDBConnection()

Dim command As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(query, con1)
Dim ra As Integer
ra = command.ExecuteNonQuery()
MsgBox(ra)
Return 1
End Function

But when i try to get the count of rows rite after the insertion using below funtion i get it as 0 though no errors are thrown while insertion


Below is the function that returns the number of rows in the database
and it always returns 0
even if insert function has been run multiple times
Public Function getSerial() As Integer

VB.NET:
Dim con1 As Data.SqlClient.SqlConnection = getDBConnection()
Dim query As String
query = "select count(*) from PersonalDetails"

Dim command As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(query, con1)
Dim dataReader As Data.SqlClient.SqlDataReader
Dim serial As Integer
dataReader = command.ExecuteReader
If dataReader.Read Then
serial = dataReader(0)
End If
dataReader.Close()
Return serial
End Function


any idea why this is not working?
its a form based app
 
Back
Top