fill a textbox from a dataset
-
Hi. This is probably real easy, but I just can't seem to figure it out. I have a dataset that returns a unique value. I would like to move that value to a textbox. No matter what I try, I can't get my code to fill the textbox. I use a dataadapter, dataset, sqlcommand and sqlparm to read a sql2000 stored procedure. I put in the city name and get out the unique city id number we use. I've run teh stored procedure separately and I know it works. Do I databind the textbox to the dataset? This is the code I'm currently using: da = new SqlDataAdapter("ap_prs_frm_addr_urbn_cmty_id", addr_urbn_conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; ds = new DataSet(); SqlParameter addr_urbn_parm; addr_urbn_parm = new SqlParameter("@cmty_desc", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ddlAddrUrbnCmty.SelectedItem.Text; addr_urbn_parm = new SqlParameter("@cmty_id", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ds.ToString(); da.SelectCommand.Parameters.Add(addr_urbn_parm); addr_urbn_conn.Open(); da.Fill(ds); addr_urbn_conn.Close(); this.txtAddrUrbnCmtyID.DataBind(); Help!!!!!!! Krisman
-
Hi. This is probably real easy, but I just can't seem to figure it out. I have a dataset that returns a unique value. I would like to move that value to a textbox. No matter what I try, I can't get my code to fill the textbox. I use a dataadapter, dataset, sqlcommand and sqlparm to read a sql2000 stored procedure. I put in the city name and get out the unique city id number we use. I've run teh stored procedure separately and I know it works. Do I databind the textbox to the dataset? This is the code I'm currently using: da = new SqlDataAdapter("ap_prs_frm_addr_urbn_cmty_id", addr_urbn_conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; ds = new DataSet(); SqlParameter addr_urbn_parm; addr_urbn_parm = new SqlParameter("@cmty_desc", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ddlAddrUrbnCmty.SelectedItem.Text; addr_urbn_parm = new SqlParameter("@cmty_id", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ds.ToString(); da.SelectCommand.Parameters.Add(addr_urbn_parm); addr_urbn_conn.Open(); da.Fill(ds); addr_urbn_conn.Close(); this.txtAddrUrbnCmtyID.DataBind(); Help!!!!!!! Krisman
try this DataSet dSet = new DataSet; ///fill DataSet here if(dSet.Tables["YourTable"].Rows.Count >0) TextBox.Text=dSet.Tables["YourTable"].Rows[0]["YouFieldName"].ToString();
-
try this DataSet dSet = new DataSet; ///fill DataSet here if(dSet.Tables["YourTable"].Rows.Count >0) TextBox.Text=dSet.Tables["YourTable"].Rows[0]["YouFieldName"].ToString();
-
Not quite getting result I thought, but at least there is a result! I'll do some more tinkering. Thanks! Krisman
Or try using a Convert.ToString() around your DataSet result. Somehow ToString sometimes returns the Class name, i.e. DataColumn
-
Hi. This is probably real easy, but I just can't seem to figure it out. I have a dataset that returns a unique value. I would like to move that value to a textbox. No matter what I try, I can't get my code to fill the textbox. I use a dataadapter, dataset, sqlcommand and sqlparm to read a sql2000 stored procedure. I put in the city name and get out the unique city id number we use. I've run teh stored procedure separately and I know it works. Do I databind the textbox to the dataset? This is the code I'm currently using: da = new SqlDataAdapter("ap_prs_frm_addr_urbn_cmty_id", addr_urbn_conn); da.SelectCommand.CommandType = CommandType.StoredProcedure; ds = new DataSet(); SqlParameter addr_urbn_parm; addr_urbn_parm = new SqlParameter("@cmty_desc", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ddlAddrUrbnCmty.SelectedItem.Text; addr_urbn_parm = new SqlParameter("@cmty_id", System.Data.SqlDbType.VarChar); addr_urbn_parm.Direction = ParameterDirection.Input; addr_urbn_parm.Value = ds.ToString(); da.SelectCommand.Parameters.Add(addr_urbn_parm); addr_urbn_conn.Open(); da.Fill(ds); addr_urbn_conn.Close(); this.txtAddrUrbnCmtyID.DataBind(); Help!!!!!!! Krisman
You can't just call DataBind() and expect .NET to solve everything for you. You need to specify to which property of the textbox you want to bind the data to, and the table and column in the dataset. Here's an example to bind the data to textbox's text property: this.txtAddrUrbnCmtyID.DataBindings.Add(new Binding("Text", ds, "tableName.columnName")); For more information, check the MSDN site for Binding Class[^]. Edbert P. Sydney, Australia.
-
You can't just call DataBind() and expect .NET to solve everything for you. You need to specify to which property of the textbox you want to bind the data to, and the table and column in the dataset. Here's an example to bind the data to textbox's text property: this.txtAddrUrbnCmtyID.DataBindings.Add(new Binding("Text", ds, "tableName.columnName")); For more information, check the MSDN site for Binding Class[^]. Edbert P. Sydney, Australia.
-
This will only work in a Windows Form, I've learned that much. I'm building WebForms, so I have to come up with different round-about ways to do things. Microsoft has never been known for being user and/or developer friendly. Krisman
I doubt that, because I have used data binding in my web project. Here's an excerpt of the code that I used:
cbApplication.DataSource = dsApplication.Tables(0)
cbApplication.DataTextField = "DirectoryName"
cbApplication.DataValueField = "IDDirectory"
cbApplication.DataBind()Edbert P. Sydney, Australia.
-
I doubt that, because I have used data binding in my web project. Here's an excerpt of the code that I used:
cbApplication.DataSource = dsApplication.Tables(0)
cbApplication.DataTextField = "DirectoryName"
cbApplication.DataValueField = "IDDirectory"
cbApplication.DataBind()Edbert P. Sydney, Australia.
I'll have to try again. But I keep getting errors and our .Net gurus where I work (our network guys) said it's because I'm trying to use a Windows Forms functionality with a Web Form. But I'm also working without a Localhost because of the way .Net was installed on our systems and servers. Krisman