क्या आपके पास अपने डेटाबेस तक पहुंच है, अगर ऐसा है तो इसे खोलें और कॉलम देखें और आवश्यकतानुसार पुनः प्राप्त करने के लिए SQL कॉल का उपयोग करें।
एक रूप एक डेटाबेस तालिका से डेटा पुनः प्राप्त करने पर एक संक्षिप्त उदाहरण: DB.mdf
तालिका नाम:: DBtable
फार्म केवल एक GataGridView नामित डेटा ग्रिड
डाटाबेस नाम शामिल
तालिका में कॉलम नाम: वर्चर (50) के रूप में नाम, int के रूप में आयु, लिंग के रूप में थोड़ा।
Private Sub DatabaseTest_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Public ConString As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\{username}\documents\visual studio 2010\Projects\Userapplication prototype v1.0\Userapplication prototype v1.0\Database\DB.mdf;" & "Integrated Security=True;User Instance=True"
Dim conn As New SqlClient.SqlConnection
Dim cmd As New SqlClient.SqlCommand
Dim da As New SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim sSQL As String = String.Empty
Try
conn = New SqlClient.SqlConnection(ConString)
conn.Open() 'connects to the database
cmd.Connection = conn
cmd.CommandType = CommandType.Text
sSQL = "SELECT * FROM DBtable" 'Sql to be executed
cmd.CommandText = sSQL 'makes the string a command
da.SelectCommand = cmd 'puts the command into the sqlDataAdapter
da.Fill(dt) 'populates the dataTable by performing the command above
Me.DataGrid.DataSource = dt 'Updates the grid using the populated dataTable
'the following is only if any errors happen:
If dt.Rows.Count = 0 Then
MsgBox("No record found!")
End If
Catch ex As Exception
MsgBox(ErrorToString)
Finally
conn.Close() 'closes the connection again so it can be accessed by other users or programs
End Try
End Sub
इस समीक्षा के लिए अपनी डेटाबेस तालिका से सभी पंक्तियों और स्तंभों लायेगा।
यदि आप केवल नाम प्राप्त करना चाहते हैं तो एसक्यूएल कॉल को इसके साथ बदलें: "डीबीटेबल से चयन नाम" इस प्रकार डेटाग्रिड व्यू केवल कॉलम नाम दिखाएगा।
मैं केवल एक रूकी हूं लेकिन मैं दृढ़ता से सलाह देता हूं कि ऑटो उत्पन्न करने वाले जादूगरों से छुटकारा पाएं। एसक्यूएल का उपयोग करके आपके पास अपने डेटाबेस तक पूर्ण पहुंच है और क्या होता है।
यह भी एक आखिरी बात है, यदि आपका डेटाबेस SQLClient का उपयोग नहीं करता है तो इसे ओलेडीबी में बदलें।
उदाहरण: "Dim conn As New SqlClient.SqlConnection
" हो जाता है: Dim conn As New OleDb.OleDbConnection
स्रोत
2013-06-05 10:26:31
मंद नाम स्ट्रिंग के रूप में() = नए स्ट्रिंग() {} प्रत्येक स्तंभ DataColumn रूप testTable.Columns में लिए नाम = column.ColumnName अगला यह इस वजह से im मंद के लिए एक स्ट्रिंग जोड़ने पसंद नहीं है स्ट्रिंग() = नई स्ट्रिंग() {} जैसा कि नाम से प्रत्येक स्तंभ DataColumn रूप testTable.Columns में नाम = column.ColumnName अगला मैं एक स्ट्रिंग सरणी के लिए एक स्ट्रिंग को जोड़ने के लिए कोशिश कर रहा हूँ के लिए, क्या हूँ मैं कर रहा यहाँ गलत है? –
जो मुझे विश्वास है वह प्राप्त करने के लिए मेरा कोड नमूना अपडेट किया गया है। –