Connecting to a SQL server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Antonio

    Connecting to a SQL server

    Good morning, all.

    First I want to apologize for the cross-posting, but this is a major part of
    the project and I would use an advice fastly.

    I am trying to design a Web app using C# to attach to a SQL server.

    As a test, I created a SQL connection and it tested successfully.

    This is my problem:

    I created a text box (txtName) which I need to bound to a specific field in
    the SQL database but I can't find it in the textbox property.

    Can someone point me to the right direction?

    Thanks,


    Antonio


  • Peter Bromberg [C# MVP]

    #2
    RE: Connecting to a SQL server

    TextBox control, whether Winforms or ASP.NET, has a Text property that holds
    the current value the user typed in, or which you have set programmaticall y,
    e.g.

    textBox1.Text is the value you want to insert into your SQL Table. Is this
    what you are looking for? Your post doesn't have that much information.

    -Peter
    --
    Co-founder, Eggheadcafe.com developer portal:

    UnBlog:





    "Antonio" wrote:
    [color=blue]
    > Good morning, all.
    >
    > First I want to apologize for the cross-posting, but this is a major part of
    > the project and I would use an advice fastly.
    >
    > I am trying to design a Web app using C# to attach to a SQL server.
    >
    > As a test, I created a SQL connection and it tested successfully.
    >
    > This is my problem:
    >
    > I created a text box (txtName) which I need to bound to a specific field in
    > the SQL database but I can't find it in the textbox property.
    >
    > Can someone point me to the right direction?
    >
    > Thanks,
    >
    >
    > Antonio
    >
    >
    >[/color]

    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Connecting to a SQL server

      Antonio,

      You don't bind columns directly to controls in .NET.

      What you do is create a SqlDataAdapter, which has insert, update,
      delete, and select commands for your table.

      You then fill a dataset with the adapter (through the Fill method). You
      bind that do your TextBox through the Bindings propery.

      Your textbox is then bound to the dataset. When you are done with it,
      you can pass the data set to the data adpater through the Update method.

      Hope this helps.


      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "Antonio" <apascarella@pa scarellas.com> wrote in message
      news:auGdneViGf MCQwveRVn-pQ@comcast.com. ..[color=blue]
      > Good morning, all.
      >
      > First I want to apologize for the cross-posting, but this is a major part
      > of the project and I would use an advice fastly.
      >
      > I am trying to design a Web app using C# to attach to a SQL server.
      >
      > As a test, I created a SQL connection and it tested successfully.
      >
      > This is my problem:
      >
      > I created a text box (txtName) which I need to bound to a specific field
      > in the SQL database but I can't find it in the textbox property.
      >
      > Can someone point me to the right direction?
      >
      > Thanks,
      >
      >
      > Antonio
      >[/color]


      Comment

      • Antonio

        #4
        Re: Connecting to a SQL server

        Hi, Peter, thank you for your reply.

        What I meant was that I am creating a web app and I need the textboxes to
        get the data from a sql server. And also, add records, update records, etc.

        But the primary value is what's retrieved from the sql.

        Antonio

        "Peter Bromberg [C# MVP]" <pbromberg@yaho o.nospammin.com > wrote in message
        news:0A6F045A-7183-4CC1-B006-504C63285887@mi crosoft.com...[color=blue]
        > TextBox control, whether Winforms or ASP.NET, has a Text property that
        > holds
        > the current value the user typed in, or which you have set
        > programmaticall y,
        > e.g.
        >
        > textBox1.Text is the value you want to insert into your SQL Table. Is this
        > what you are looking for? Your post doesn't have that much information.
        >
        > -Peter
        > --
        > Co-founder, Eggheadcafe.com developer portal:
        > http://www.eggheadcafe.com
        > UnBlog:
        > http://petesbloggerama.blogspot.com
        >
        >
        >
        >
        > "Antonio" wrote:
        >[color=green]
        >> Good morning, all.
        >>
        >> First I want to apologize for the cross-posting, but this is a major part
        >> of
        >> the project and I would use an advice fastly.
        >>
        >> I am trying to design a Web app using C# to attach to a SQL server.
        >>
        >> As a test, I created a SQL connection and it tested successfully.
        >>
        >> This is my problem:
        >>
        >> I created a text box (txtName) which I need to bound to a specific field
        >> in
        >> the SQL database but I can't find it in the textbox property.
        >>
        >> Can someone point me to the right direction?
        >>
        >> Thanks,
        >>
        >>
        >> Antonio
        >>
        >>
        >>[/color][/color]


        Comment

        • Ignacio Machin \( .NET/ C# MVP \)

          #5
          Re: Connecting to a SQL server

          Hi,

          [color=blue]
          > I created a text box (txtName) which I need to bound to a specific field
          > in the SQL database but I can't find it in the textbox property.[/color]

          Most probably your query will return more than one row, how you are dealing
          with this?

          As the other posters (nicholas ) said you need to load it first in a
          dataset/datatable then you can bind it to the textbox.

          As you saw the textbox itself does not support binding , you have to assign
          the value directly using TextBox.Text or in the aspx page using <%# %> tags
          ..


          btw, if you are going to cross-post (which you should not ! ) select the
          correct groups , posting to
          microsoft.publi c.dotnet.langua ges.vc,microsof t.public.dotnet .vc.general as
          nothing to do with the problem at hand



          cheers,

          --
          Ignacio Machin,
          ignacio.machin AT dot.state.fl.us
          Florida Department Of Transportation

          [color=blue]
          > Can someone point me to the right direction?
          >
          > Thanks,
          >
          >
          > Antonio
          >[/color]


          Comment

          • MasterChief

            #6
            Re: Connecting to a SQL server

            using System.Data.Sql Client

            should help :-)

            "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
            schrieb im Newsbeitrag news:e8$CCaz#FH A.3392@TK2MSFTN GP14.phx.gbl...[color=blue]
            > Hi,
            >
            >[color=green]
            > > I created a text box (txtName) which I need to bound to a specific field
            > > in the SQL database but I can't find it in the textbox property.[/color]
            >
            > Most probably your query will return more than one row, how you are[/color]
            dealing[color=blue]
            > with this?
            >
            > As the other posters (nicholas ) said you need to load it first in a
            > dataset/datatable then you can bind it to the textbox.
            >
            > As you saw the textbox itself does not support binding , you have to[/color]
            assign[color=blue]
            > the value directly using TextBox.Text or in the aspx page using <%# %>[/color]
            tags[color=blue]
            > .
            >
            >
            > btw, if you are going to cross-post (which you should not ! ) select the
            > correct groups , posting to
            > microsoft.publi c.dotnet.langua ges.vc,microsof t.public.dotnet .vc.general as
            > nothing to do with the problem at hand
            >
            >
            >
            > cheers,
            >
            > --
            > Ignacio Machin,
            > ignacio.machin AT dot.state.fl.us
            > Florida Department Of Transportation
            >
            >[color=green]
            > > Can someone point me to the right direction?
            > >
            > > Thanks,
            > >
            > >
            > > Antonio
            > >[/color]
            >
            >[/color]


            Comment

            • MuZZy

              #7
              Re: Connecting to a SQL server

              What do you guys mean by "...As you saw the textbox itself does not
              support binding..."? It does support binding to a datatable as any other
              control does.

              txtBox.DataBind ings.Add("Text" , drDataRow, "Data table's column name");

              Works for me in 1000 places in our app...

              Let me know if you need any more explanation

              MuZZy




              MasterChief wrote:[color=blue]
              > using System.Data.Sql Client
              >
              > should help :-)
              >
              > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us >
              > schrieb im Newsbeitrag news:e8$CCaz#FH A.3392@TK2MSFTN GP14.phx.gbl...[color=green]
              >> Hi,
              >>
              >>[color=darkred]
              >>> I created a text box (txtName) which I need to bound to a specific field
              >>> in the SQL database but I can't find it in the textbox property.[/color]
              >> Most probably your query will return more than one row, how you are[/color]
              > dealing[color=green]
              >> with this?
              >>
              >> As the other posters (nicholas ) said you need to load it first in a
              >> dataset/datatable then you can bind it to the textbox.
              >>
              >> As you saw the textbox itself does not support binding , you have to[/color]
              > assign[color=green]
              >> the value directly using TextBox.Text or in the aspx page using <%# %>[/color]
              > tags[color=green]
              >> .
              >>
              >>
              >> btw, if you are going to cross-post (which you should not ! ) select the
              >> correct groups , posting to
              >> microsoft.publi c.dotnet.langua ges.vc,microsof t.public.dotnet .vc.general as
              >> nothing to do with the problem at hand
              >>
              >>
              >>
              >> cheers,
              >>
              >> --
              >> Ignacio Machin,
              >> ignacio.machin AT dot.state.fl.us
              >> Florida Department Of Transportation
              >>
              >>[color=darkred]
              >>> Can someone point me to the right direction?
              >>>
              >>> Thanks,
              >>>
              >>>
              >>> Antonio
              >>>[/color]
              >>[/color]
              >
              >[/color]

              Comment

              Working...