Data Confusion
Hi, I am new to C# and Visual Studio.
I am trying to make a web page which accesses a database.
All I want to do is have a few textboxes = to data in the DB but I'm flummuxedf by the new Visual Studio 2005.
I tried coding the ADO.NET connection strings myself but it wouldn't work so I decided to use the API to set up the data connection and the dataset.
I want to set Textbox1.Text to a cell in my DataTable called MainTable in my dataset which is called Dataset1.
I was going to try the following:
Textbox1.Text = DataSet1.Tables["TableName"].Rows[1].ItemArray[2].ToString();
However VS 2005 DataSets are Typed and no longer have the .Tables method.
I've read articles such as http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/newdtastvs05.asp
and others like it but none of them solve my problem.
they talk about a data source Tab, I think this only applies to applications and VB as there is no data source tab in my c# VS website api.
I'm flummoxed,
Please advise.
Thanks
# 1 Re: Data Confusion
The code below works fine for me:
using System;
using System.Data;
using System.Data.OleDb;
using System.Windows.Forms;
namespace MyApp
{
public partial class Form1 : Form
{
private DataSet DataSet1 = new DataSet();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
GetData();
textBox1.Text = DataSet1.Tables["MainTable"].Rows[0].ItemArray[2].ToString();
}
private void GetData()
{
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"d:\\path\\nwind.mdb\"";
OleDbConnection cn = new OleDbConnection(connectionString);
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM Customers", cn);
da.Fill(DataSet1, "MainTable");
cn.Close();
}
}
}
# 2 Re: Data Confusion
Hi Phil, Thanks for the reply. I gave your code a shot with the location of my db in it. However, VS is still rejecting it. It doesn't accept the connecting string.
I'm totally lost. I will be having a word with my lecturer about this on monday.
thanks anyway