Hi,
How can i fill a textbox with a tablefield that’s in a sql server.
I only can explain in Delphi pascal it looks like this:
Begin
Edit1.Text := adoquery1.fieldbyname('a field').asstring;
end;
Thanks a lot for the help.
I 'am really a VS noob but willing to try.
Grtz
Dipsy.

How to fill a textbox in a website application in VS 2005
SirSmokey
try replace
DataSet1.driverDataTable mytable = DataSet1.driver.DataTable();
TextBox1.Text = mytable.Rows[0]["Drivername"].ToString();
by:
TextBox1.Text = DataSet1[0].Rows[0]["Drivername"].ToString();Xuan
Dgrumbli
Sarah,
Thank you for your detailed reply. I have it working within a minute. I really like to now one more thing.
Why create a datset and adaptor trough the wizzard if i have to make a instance of the dataset,datatabel and adaptor manually In other words what does the wizzard do for me
It really sounds weird to me because in Delphi you can access the dataset (table or query) just by opening it (if you first connect the dataset to the right database in run or designtime).
But now at least i now what i'm doing.....hopefully
Thanks again for the detailed explanation this really helps me to understand how stuff works in VS
Dipsy aka Aschwin.
riverwalker
Hi,
Thanks for the answer but i am still not where i want to be.
This i have got sofar:
I created a dataset and left the name default
in the dataset i create a connection to a table in my database called "driver"
Then i want to put in this code:
DataSet1.driverDataTable mytable = DataSet1.driver.DataTable();
TextBox1.Text = mytable.Rows["Drivername"].ToString();
The compiler comes whith the following message:
Error 1 'DataSet1.driverDataTable' is a 'type', which is not valid in the given context
Sorry about this very basic question but i hope someone will answer it.
Thanks
Dipsy.
Kurt Yue
OK,
But when i change my code to
DataSet1.driverDataTable mytable = DataSet1.driver.DataTable();
TextBox1.Text = mytable.Rows[0]["Drivername"].ToString();
The compiler still will give the following error:
Error 1 'DataSet1.driverDataTable' is a 'type', which is not valid in the given context.
I don't no what this error means.
Please help.
Grtz
Dipsy.
Prasant
Xuan,
Thanks for the reply but when i write the code the compiler comes with the following message:
Error 1 'DataSet1' is a 'type' but is used like a 'variable'
Please help i realy want to now what is wrong so i can undertand what is happening
Thanks,
Dipsy
nomad#1
I assume that DataSet1 is a typed dataset that you generated through the VS wizards, is that right
This line of code:
failed with "'DataSet1.driverDataTable' is a 'type', which is not valid in the given context" because you are missing a "new". It would have to look like this for the compiler to accept it:
This line of code:fails because DataSet1 is a type, not an instance of that type.
What you need here is an instance of DataSet1 that has been filled with data. If you use the first example I gave above (with the "new" added), you will have an empty DataTable, so you can't directly start accessing rows in that table. You'd have to create a DataAdapter that you'd use to fill the DataSet, then you would use the last line of code above, except you'd use myTable instead of DataSet1[0].
The wizards may have created the DataAdapter (or TableAdapter) for you, depending on how you created the DataSet. You probably have a DataSet1.xsd file somewhere in the project. Take a look at that and you'll see the classes and methods the wizard created. You will probably see a graphic that shows the table structure for driver, and also a table adapter, probably called driverTableAdapter. You should also see this DataSet in the Data Sources window in VS. You can drag the table onto your form and it will automatically create some stuff for you (bindings, code to fill the dataset, etc), but just to get this running you don't have to do that. The following would be the minimal code to create the DataTable and fill it, then pull one value from it. You would normally create and fill the DataTable during initialization, like during Form_Load, but the bottom line is you just need to do this somewhere before you can fill your textbox.
Thanks,
Sarah
Mr. Bob Dobalina
try replace
DataSet1.driverDataTable mytable = DataSet1.driver.DataTable();
TextBox1.Text = mytable.Rows[0]["Drivername"].ToString();
by:
TextBox1.Text = DataSet1[0].Rows[0]["Drivername"].ToString();Xuan
GerardL
Well, first you need a datasource, then you will have a table you can access.
edit1.Text = myTable.Rows[0]["columnname"].ToString();
Something like that. You can reference columns by index or name.
JohnBrack
OK, you still need to do what I suggested. The Rows collection is a collection of rows, which you can access via numeric index. THEN you can apply a column name.
TextBox1.Text = mytable.Rows[0]["Drivername"].ToString();
xerodiac
If you used the wizard to create the instances of the objects, you don't need to also use the code I gave, you just need to access the right objects that the wizard generated. There are several ways to create a typed dataset with the wizards, so depending on how you did it, you might not have those objects, which is why I gave example code based on the most basic scenario. For example, you can add the DataSet class without adding anything else, and in that case, you would need to use code like I gave.
If you created a Data Source, then dragged it to your form and let the wizard create all of the objects, you should have all the code you need to create the DataSet and TableAdapter, and fill the DataSet. In that case, you probably have an object instance called dataSet1.driver. Note the lowercase "d" in dataSet1 -- this is the instance that the wizard created, as opposed to DataSet1, which is the type. If you have that, you can directly access it, instead of creating and filling a new one. Example:
The variable names I am using may not match exactly to what you have, but I think this should be close. If you want to see what the wizard is doing for you with those instances, open the Form1.Designer.cs file. For example, in my test project, I have the following:
You don't need to modify this file directly, but I always understand things better when I see the plumbing, so I like this file. :)
If you got it working at all, you're making progress, so that's good. :) You may just need to tweak things a little to work in the cleanest way possible.
Thanks,
Sarah