8 Replies - 465 Views - Last Post: 03 March 2011 - 12:31 PM Rate Topic: -----

#1 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

extracting info and putting it into textboxes

Posted 02 March 2011 - 02:36 AM

i have as function that i am using to extract all information in my table and it is working great when i want the stuff to be presented in a datagridview but now i want the stuff to be put into relevant textboxes and textbox does not accept the datasource method so can anyone help
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)



Is This A Good Question/Topic? 0
  • +

Replies To: extracting info and putting it into textboxes

#2 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: extracting info and putting it into textboxes

Posted 02 March 2011 - 08:23 AM

THis is an example of how to bind it to a datatable.

 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

Was This Post Helpful? 1
  • +
  • -

#3 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

Re: extracting info and putting it into textboxes

Posted 02 March 2011 - 08:40 AM

View PostShadar, on 02 March 2011 - 08:23 AM, said:

THis is an example of how to bind it to a datatable.

 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
Was This Post Helpful? 0
  • +
  • -

#4 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

Re: extracting info and putting it into textboxes

Posted 02 March 2011 - 08:49 AM

View Posttendaimare, on 02 March 2011 - 08:40 AM, said:

View PostShadar, on 02 March 2011 - 08:23 AM, said:

THis is an example of how to bind it to a datatable.

 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?

Was This Post Helpful? 0
  • +
  • -

#5 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: extracting info and putting it into textboxes

Posted 02 March 2011 - 09:33 AM

View Posttendaimare, on 02 March 2011 - 09:49 AM, said:

View Posttendaimare, on 02 March 2011 - 08:40 AM, said:

View PostShadar, on 02 March 2011 - 08:23 AM, said:

THis is an example of how to bind it to a datatable.

 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

Was This Post Helpful? 1
  • +
  • -

#6 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

Re: extracting info and putting it into textboxes

Posted 03 March 2011 - 12:23 AM

View PostShadar, on 02 March 2011 - 09:33 AM, said:

View Posttendaimare, on 02 March 2011 - 09:49 AM, said:

View Posttendaimare, on 02 March 2011 - 08:40 AM, said:

View PostShadar, on 02 March 2011 - 08:23 AM, said:

THis is an example of how to bind it to a datatable.

 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
Was This Post Helpful? 0
  • +
  • -

#7 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: extracting info and putting it into textboxes

Posted 03 March 2011 - 09:20 AM

Show me your GetBindingSource Function
Was This Post Helpful? 1
  • +
  • -

#8 tendaimare  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 170
  • Joined: 04-November 10

Re: extracting info and putting it into textboxes

Posted 03 March 2011 - 09:35 AM

Public Shared Function GetBindingSource(ByVal SqlCmd As SqlCommand) As BindingSource
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
Was This Post Helpful? 0
  • +
  • -

#9 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: extracting info and putting it into textboxes

Posted 03 March 2011 - 12:31 PM

OK...now that I see what you are doing this is the line you need.

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

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1