can i retrieve the primary keys of a table?
-
i want to retrieve of a table whose schema and other constraints i do not know basically , i had given user opurtunity to browse the database (and select any table) and based on that i will display the priary keys(if it does not had primey keys then a msgbox will be displayed) is there any method to know wheteher table has primary keys and to bind that column to the combobox plz help a code snippet will be more helpfull....
-
i want to retrieve of a table whose schema and other constraints i do not know basically , i had given user opurtunity to browse the database (and select any table) and based on that i will display the priary keys(if it does not had primey keys then a msgbox will be displayed) is there any method to know wheteher table has primary keys and to bind that column to the combobox plz help a code snippet will be more helpfull....
You can use the stored proc sp_primarykeys Best of luck Forever Developing
-
You can use the stored proc sp_primarykeys Best of luck Forever Developing
-
I was not sure if you were using OLEDB or ODBC so I did it in OLEDB. Private Sub cmdFindPrimary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFindPrimary.Click Try Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=V:\VBScratchPad\test.mdb;" Dim cn As OleDbConnection = New OleDbConnection(ConnString) cn.Open() Dim da As New OleDbDataAdapter("Select * from Test", cn) Dim ds As New DataSet("TESTING") da.FillSchema(ds, SchemaType.Mapped) For i As Integer = 0 To ds.Tables(0).PrimaryKey.GetUpperBound(0) Console.WriteLine(ds.Tables(0).PrimaryKey(i).ColumnName) Next Catch ex As ApplicationException MessageBox.Show(ex.ToString()) End Try End Sub Best of Luck Forever Developing
-
I was not sure if you were using OLEDB or ODBC so I did it in OLEDB. Private Sub cmdFindPrimary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFindPrimary.Click Try Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=V:\VBScratchPad\test.mdb;" Dim cn As OleDbConnection = New OleDbConnection(ConnString) cn.Open() Dim da As New OleDbDataAdapter("Select * from Test", cn) Dim ds As New DataSet("TESTING") da.FillSchema(ds, SchemaType.Mapped) For i As Integer = 0 To ds.Tables(0).PrimaryKey.GetUpperBound(0) Console.WriteLine(ds.Tables(0).PrimaryKey(i).ColumnName) Next Catch ex As ApplicationException MessageBox.Show(ex.ToString()) End Try End Sub Best of Luck Forever Developing
i had written the code but i m still getting exceptions here is my code con is oledbconnection adap is oledbdataadapter ds is dataset con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=D:\Documents and Settings\sumit\My Documents\db1.mdb") adap = New OleDbDataAdapter("select * from table4", con) ds = New DataSet("testing") adap.FillSchema(ds, SchemaType.Mapped) Dim i As Integer Try For i = 0 To ds.Tables("table4").PrimaryKey.GetUpperBound(0) combobox1.items.add(ds.Tables("Table4").PrimaryKey(i).ColumnName()) Next Catch ex As System.Exception MsgBxox(ex.Source + " " + ex.Message + " " + ex.ToString) End Try End Sub and i m getting the exception "object refrence not set to instance of object" help plz
-
i had written the code but i m still getting exceptions here is my code con is oledbconnection adap is oledbdataadapter ds is dataset con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Password=;User ID=Admin;Data Source=D:\Documents and Settings\sumit\My Documents\db1.mdb") adap = New OleDbDataAdapter("select * from table4", con) ds = New DataSet("testing") adap.FillSchema(ds, SchemaType.Mapped) Dim i As Integer Try For i = 0 To ds.Tables("table4").PrimaryKey.GetUpperBound(0) combobox1.items.add(ds.Tables("Table4").PrimaryKey(i).ColumnName()) Next Catch ex As System.Exception MsgBxox(ex.Source + " " + ex.Message + " " + ex.ToString) End Try End Sub and i m getting the exception "object refrence not set to instance of object" help plz
Not sure why this is but I found a solution to you problem For i = 0 To ds.Tables(0).PrimaryKey.GetUpperBound(0) ComboBox1.Items.Add(ds.Tables(0).PrimaryKey(i).ColumnName()) Next it seems that when filling the schema you cannot refer to the table by its name but only by index number or the value "Table" Forever Developing
-
Not sure why this is but I found a solution to you problem For i = 0 To ds.Tables(0).PrimaryKey.GetUpperBound(0) ComboBox1.Items.Add(ds.Tables(0).PrimaryKey(i).ColumnName()) Next it seems that when filling the schema you cannot refer to the table by its name but only by index number or the value "Table" Forever Developing