I am having trouble getting table data from my SQLExpress connected databases to bind to the textboxes in my form.
I can perform a grid view of the tables data just fine. Any suggestionson what am I missing in the form design
Windows Forms Data Controls and Databinding
I am having trouble getting table data from my SQLExpress connected databases to bind to the textboxes in my form.
I can perform a grid view of the tables data just fine. Any suggestionson what am I missing in the form design
could you please show your code,it is hard to tell you where is the problem
maybe you should check whether you have set datasource,datamember,or fill the dataset.
here is a small demo hope help you
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace WindowsApplication2
{
class DBAccess
{
public DataSet getData()
{
SqlConnection conn = new SqlConnection("Data Source=(local)\\sqlexpress;Initial Catalog=Test;Integrated Security=True;Pooling=False");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("SELECT TB_ID.* FROM TB_ID", conn);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
return ds;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
DBAccess DB = new DBAccess();
DataSet ds = DB.getData();
this.dataGridView1.DataSource = ds.Tables[0];
BindingSource BS = new BindingSource();
BS.DataSource = ds.Tables[0];
this.textBox1.DataBindings.Add("Text",BS,"ID",false,DataSourceUpdateMode.OnPropertyChanged);
}
}
}
I don't have any code to show. What I am interested in is why, in the devleoper environment, I can't just bind a datasource to a textbox in a form like I do in MS-ACCESS.
This SQL Server Developer Edition is making it way too hard to do a simple task. I am saying when you elect view all the table data to a grid, that works. I want to add text boxes to a form and it complains of a binding errror when I do this.