EDN Admin
Well-known member
Hello,
I am using VB.Net 2010 and SQL Server 2005 Enterprise Edition
I have created a table named customer having columns (id int, fullname varchar(50)) and id is my primary key
I have created a Class Library for retrieving data.
to retrieve data I am using following code...
<div style="color:black; background-color:white
<pre><span style="color:blue Public <span style="color:blue Sub getData(<span style="color:blue ByVal TableName <span style="color:blue As <span style="color:blue String, <span style="color:blue ByVal LinkToDb <span style="color:blue As SqlConnection, <span style="color:blue ByRef Adapter <span style="color:blue As SqlDataAdapter, <span style="color:blue ByRef DS <span style="color:blue As DataSet)
<span style="color:green ----- sends data from database
<span style="color:blue Dim sqlCmd <span style="color:blue As SqlCommand
<span style="color:blue Dim Query <span style="color:blue As <span style="color:blue String
<span style="color:blue Try
Query = <span style="color:#a31515 "Select * from " & TableName
sqlCmd = <span style="color:blue New SqlCommand(Query, LinkToDb)
Adapter.SelectCommand = sqlCmd
Adapter.Fill(DS)
sqlCmd.Dispose()
<span style="color:blue Catch ex <span style="color:blue As SqlException
MsgBox(<span style="color:#a31515 "Unable to retrive data from Database: " & ex.Message, MsgBoxStyle.Critical, <span style="color:#a31515 "Critical Error")
<span style="color:blue Catch ex <span style="color:blue As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, <span style="color:#a31515 "Critical Error")
<span style="color:blue End <span style="color:blue Try
<span style="color:blue End <span style="color:blue Sub
[/code]
<br/>
Data comes inside the dataset from the Customer table but its Primary key is not preserved.
Whenever m checking for the primary key it says Primary Key = False
I am using following function for checking primary key.
<div style="color:black; background-color:white
<pre> <span style="color:blue Private <span style="color:blue Function IsPrimaryKeyColumn(<span style="color:blue ByRef Table <span style="color:blue As DataTable, <span style="color:blue ByRef Column <span style="color:blue As DataColumn) <span style="color:blue As <span style="color:blue Boolean
<span style="color:blue Return Array.IndexOf(Table.PrimaryKey, Column) >= 0
<span style="color:blue End <span style="color:blue Function
[/code]
<br/>
Why is this happening ??
Please Help...
<
NB<br/>
View the full article
I am using VB.Net 2010 and SQL Server 2005 Enterprise Edition
I have created a table named customer having columns (id int, fullname varchar(50)) and id is my primary key
I have created a Class Library for retrieving data.
to retrieve data I am using following code...
<div style="color:black; background-color:white
<pre><span style="color:blue Public <span style="color:blue Sub getData(<span style="color:blue ByVal TableName <span style="color:blue As <span style="color:blue String, <span style="color:blue ByVal LinkToDb <span style="color:blue As SqlConnection, <span style="color:blue ByRef Adapter <span style="color:blue As SqlDataAdapter, <span style="color:blue ByRef DS <span style="color:blue As DataSet)
<span style="color:green ----- sends data from database
<span style="color:blue Dim sqlCmd <span style="color:blue As SqlCommand
<span style="color:blue Dim Query <span style="color:blue As <span style="color:blue String
<span style="color:blue Try
Query = <span style="color:#a31515 "Select * from " & TableName
sqlCmd = <span style="color:blue New SqlCommand(Query, LinkToDb)
Adapter.SelectCommand = sqlCmd
Adapter.Fill(DS)
sqlCmd.Dispose()
<span style="color:blue Catch ex <span style="color:blue As SqlException
MsgBox(<span style="color:#a31515 "Unable to retrive data from Database: " & ex.Message, MsgBoxStyle.Critical, <span style="color:#a31515 "Critical Error")
<span style="color:blue Catch ex <span style="color:blue As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, <span style="color:#a31515 "Critical Error")
<span style="color:blue End <span style="color:blue Try
<span style="color:blue End <span style="color:blue Sub
[/code]
<br/>
Data comes inside the dataset from the Customer table but its Primary key is not preserved.
Whenever m checking for the primary key it says Primary Key = False
I am using following function for checking primary key.
<div style="color:black; background-color:white
<pre> <span style="color:blue Private <span style="color:blue Function IsPrimaryKeyColumn(<span style="color:blue ByRef Table <span style="color:blue As DataTable, <span style="color:blue ByRef Column <span style="color:blue As DataColumn) <span style="color:blue As <span style="color:blue Boolean
<span style="color:blue Return Array.IndexOf(Table.PrimaryKey, Column) >= 0
<span style="color:blue End <span style="color:blue Function
[/code]
<br/>
Why is this happening ??
Please Help...
<
NB<br/>
View the full article