Connecting to a SQL server

  • Thread starter Thread starter Antonio
  • Start date Start date
A

Antonio

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
 
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 programmatically,
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
 
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.
 
Hi,

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.

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.public.dotnet.languages.vc,microsoft.public.dotnet.vc.general as
nothing to do with the problem at hand



cheers,
 
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
 
using System.Data.SqlClient

should help :-)

Ignacio Machin ( .NET/ C# MVP ) said:
Hi,



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.public.dotnet.languages.vc,microsoft.public.dotnet.vc.general as
nothing to do with the problem at hand



cheers,
 
Back
Top