1
Public Shared Function GetRecords(ByVal myStoredProcedure As String) As BindingSource
Dim sSQL As String = myStoredProcedure
Dim Conn As New SqlConnection
Conn = MyFormz.connec.ConnWeb2()
Dim cmdGetRecords As New SqlCommand()
Dim daGetRecords As New SqlDataAdapter()
Dim dsGetRecords As New DataSet()
cmdGetRecords.Parameters.Clear()
Try
With cmdGetRecords
.CommandText = sSQL
.CommandType = CommandType.StoredProcedure
.Connection = Conn
End With
Conn.Open()
Dim oBindingSource As BindingSource = GetBindingSource(cmdGetRecords)
If Not oBindingSource Is Nothing Then
Return oBindingSource
Else
Throw New Exception("There was no BindingSource returned")
Return Nothing
End If
Catch ex As Exception
Return Nothing
Finally
Conn.Close()
End Try
End Function
2
DataGridView1.DataSource = DirectCast(ClassClass.GetRecords("udp_tblArea_lst"), BindingSource)
extracting info and putting it into textboxes
Page 1 of 18 Replies - 388 Views - Last Post: 03 March 2011 - 12:31 PM
#1
extracting info and putting it into textboxes
Posted 02 March 2011 - 02:36 AM
Replies To: extracting info and putting it into textboxes
#2
Re: extracting info and putting it into textboxes
Posted 02 March 2011 - 08:23 AM
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
End Sub
This post has been edited by Shadar: 02 March 2011 - 08:26 AM
#3
Re: extracting info and putting it into textboxes
Posted 02 March 2011 - 08:40 AM
Shadar, on 02 March 2011 - 08:23 AM, said:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
End Sub
ALTER PROC [dbo].[udp_tblArea_Other_lst] AS SET NOCOUNT ON SELECT [Category_ID], [Category] FROM tblArea_Other SET NOCOUNT OFF
ALTER PROC [dbo].[udp_tblArea_sel] @Category_ID bigint AS SET NOCOUNT ON SELECT [Category_ID], [Category], [Area_Name] FROM tblArea WHERE [Category_ID] = @Category_ID SET NOCOUNT OFF
i am using these stored procedures for extracting all data in a datatable so how do i adjust the code
#4
Re: extracting info and putting it into textboxes
Posted 02 March 2011 - 08:49 AM
tendaimare, on 02 March 2011 - 08:40 AM, said:
Shadar, on 02 March 2011 - 08:23 AM, said:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
End Sub
ALTER PROC [dbo].[udp_tblArea_Other_lst] AS SET NOCOUNT ON SELECT [Category_ID], [Category] FROM tblArea_Other SET NOCOUNT OFF
ALTER PROC [dbo].[udp_tblArea_sel] @Category_ID bigint AS SET NOCOUNT ON SELECT [Category_ID], [Category], [Area_Name] FROM tblArea WHERE [Category_ID] = @Category_ID SET NOCOUNT OFF
i am using these stored procedures for extracting all data in a datatable so how do i adjust the codeand by the way cm_SQLServer is supposed to be what exactly?
#5
Re: extracting info and putting it into textboxes
Posted 02 March 2011 - 09:33 AM
tendaimare, on 02 March 2011 - 09:49 AM, said:
tendaimare, on 02 March 2011 - 08:40 AM, said:
Shadar, on 02 March 2011 - 08:23 AM, said:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
End Sub
ALTER PROC [dbo].[udp_tblArea_Other_lst] AS SET NOCOUNT ON SELECT [Category_ID], [Category] FROM tblArea_Other SET NOCOUNT OFF
ALTER PROC [dbo].[udp_tblArea_sel] @Category_ID bigint AS SET NOCOUNT ON SELECT [Category_ID], [Category], [Area_Name] FROM tblArea WHERE [Category_ID] = @Category_ID SET NOCOUNT OFF
i am using these stored procedures for extracting all data in a datatable so how do i adjust the codeand by the way cm_SQLServer is supposed to be what exactly?
Don't pay attention to the
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
line. That is simply a class I wrote to make getting a datatable or dataset back easier. (I got tired of declaring datqa adapter and commands etc)
The line that you need to use is below. Just replace the dt with your dataset variable.
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
BTW: I didn't see where you are filling your dataset in your code.
This post has been edited by Shadar: 02 March 2011 - 09:36 AM
#6
Re: extracting info and putting it into textboxes
Posted 03 March 2011 - 12:23 AM
Shadar, on 02 March 2011 - 09:33 AM, said:
tendaimare, on 02 March 2011 - 09:49 AM, said:
tendaimare, on 02 March 2011 - 08:40 AM, said:
Shadar, on 02 March 2011 - 08:23 AM, said:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
End Sub
ALTER PROC [dbo].[udp_tblArea_Other_lst] AS SET NOCOUNT ON SELECT [Category_ID], [Category] FROM tblArea_Other SET NOCOUNT OFF
ALTER PROC [dbo].[udp_tblArea_sel] @Category_ID bigint AS SET NOCOUNT ON SELECT [Category_ID], [Category], [Area_Name] FROM tblArea WHERE [Category_ID] = @Category_ID SET NOCOUNT OFF
i am using these stored procedures for extracting all data in a datatable so how do i adjust the codeand by the way cm_SQLServer is supposed to be what exactly?
Don't pay attention to the
dt = cm_SQLSERVER.GetDataTable("Select * from employees", CommandType.Text)
line. That is simply a class I wrote to make getting a datatable or dataset back easier. (I got tired of declaring datqa adapter and commands etc)
The line that you need to use is below. Just replace the dt with your dataset variable.
TextBox1.DataBindings.Add(New Binding("Text", dt, "lastname"))
BTW: I didn't see where you are filling your dataset in your code.
i am using a binding source(look at line line 18-20) in my original code(the code i posted the first time) and the other thing is i am using a stored procedure
where does it get involved on the code you posted coz i'm lost now
i am using a binding source(look at line line 18-20) in my original code(the code i posted the first time) and the other thing is i am using a stored procedure
where does it get involved on the code you posted coz i'm lost now
#7
Re: extracting info and putting it into textboxes
Posted 03 March 2011 - 09:20 AM
#8
Re: extracting info and putting it into textboxes
Posted 03 March 2011 - 09:35 AM
Dim oBindingSource As New BindingSource()
Dim Adapter As New SqlDataAdapter(SqlCmd)
' Populate a new data table and bind it to the BindingSource.
Dim dTable As New DataTable()
SqlCmd.CommandTimeout = 240
dTable.Locale = System.Globalization.CultureInfo.InvariantCulture
Try
Adapter.Fill(dTable)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error getting BindingSource", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
oBindingSource.DataSource = dTable
Return oBindingSource
End Function
#9
Re: extracting info and putting it into textboxes
Posted 03 March 2011 - 12:31 PM
TextBox1.DataBindings.Add(New Binding("Text", oBindingSource, "NameOfFieldToBindTextBoxTo"))
Add this line after you get the binding source and modify it for each textbox.
Example:
TextBox1.DataBindings.Add(New Binding("Text", oBindingSource, "NameOfFieldToBindTextBoxTo"))
TextBox2.DataBindings.Add(New Binding("Text", oBindingSource, "NameOfFieldToBindTextBoxTo2"))
This post has been edited by Shadar: 03 March 2011 - 12:38 PM
|
|

New Topic/Question
Reply




MultiQuote




|