compactframework >> Filling dataset with form data

by bGVhcm5pbmdORVQ » Tue, 26 Jul 2005 01:01:03 GMT

I have a few textboxes to hold x, y, z dimensions and weight per item. The
user may have different number of items so I will have one set of these
textboxes with an add button. Upon click, I would like to show the data in a
tabular form with proper headings for each of the items on the same page
before finally submitting it to the DB. Is there any way I can use DataTable,
DataGrid etc to show the data in a neat format?
I searched the net for my question. I need to know:
- how to use datagrid to send information to it.
- how to retrieve it to submit it to the DB.
TIA


compactframework >> RE: Filling dataset with form data

by QWxleCBZYWtobmluIFtNVlBd » Tue, 26 Jul 2005 01:15:08 GMT


compactframework >> RE: Filling dataset with form data

by bGVhcm5pbmdORVQ » Tue, 26 Jul 2005 01:26:02 GMT

I actually want to save the data into a datagrid first(using the inputs from
different textboxes) and then eventually submit it to the DB for the first
time. The webpage you recommended seems to only have examples of filling the
datagrid with a table in the DB. Please advice if I am wrong.

Thanks.

compactframework >> RE: Filling dataset with form data

by QWxleCBZYWtobmluIFtNVlBd » Tue, 26 Jul 2005 01:55:03 GMT

Create a DataDaset or DataTable, populate it with your data from TextBoxes
and bind it to the DataGrid..
Something like that (not tested)

//Create DateTable
DataTable dt = new DataTable("table");

//add to columns collection
DataColumn dc = dt.Columns.Add("Column 1");
dc.DataType = typeof(string);
dc.AllowDBNull = true;

dc = dt.Columns.Add("Column 2");
dc.DataType = typeof(string);
dc.AllowDBNull = true;

dc = dt.Columns.Add("Column 3");
dc.DataType = typeof(string);
dc.AllowDBNull = true;

//Update values
DataRow dataRow = dt.NewRow();
dataRow["Column 1"] = textBox1.Text;
...

Bind it to the grid:

dataGrid.DataSource - dt;

compactframework >> RE: Filling dataset with form data

by ilyatum » Tue, 26 Jul 2005 02:09:31 GMT

DataGrid only shows data from DataSource, it does not have data storage at
all.
You can't "save the data into a datagrid" just like you can't pour water
into the bucket's reflection in the mirror.
You should add data to the grid's data source (e.g. DataTable) and push
this update to the data base at your convenience.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
< XXXX@XXXXX.COM >
< XXXX@XXXXX.COM >
microsoft.public.dotnet.framework.compactframework:32919
from
first
the

compactframework >> RE: Filling dataset with form data

by bGVhcm5pbmdORVQ » Fri, 29 Jul 2005 01:25:05 GMT

Hi
Your reply did help me databind the datatable to datagrid, but I have
another question: I create the datatable in page_load and databind it to a
datagrid. In my btnAdd_Click method( which should just add another row with
the new textbox values), I am unable to use the column names. I even tried
declaring the datatable in class scope. Is there a way I can databind the
datagrid back to a datatable in that method, add a row and at the end,
databind the datatable back again? I hope you get what I'm saying. Thanks
again.

Similar Threads

1. Filling dataset with form data

I have a few textboxes to hold x, y, z dimensions and weight per item. The 
user may have different number of items so I will have one set of these 
textboxes with an add button. Upon click, I would like to show the data in a 
tabular form with proper headings for each of the items on the same page 
before finally submitting it to the DB. Is there any way I can use DataTable, 
DataGrid etc to show the data in a neat format? 
TIA

2. Filling a strongly-typed dataset using Data Access Application Block (DAAB) June 2005 Version - ADO.Net

3. Problem while filling the dataset where the data source is a .CSV file

HI,
I am trying to reading a .csv file from a remote desktop.

the connection string that i am using is as follows:

strConn = "Provider=MS Remote;"+"Remote Server=//<ComputerName>/
<FolederName>;" + " Remote Provider=Microsoft.Jet.OLEDB.4.0;"+"Data
Source="+@"d:/trial/try1.csv"+";"+"Extended
Properties='text;HDR=Yes;FMT=Delimited'";

With this connection string i am able to open the connection but when
i try to fill the data set it gives me the error:

"Specified Cast is not valid"

the line is

da.Fill(ds);

where 'da' is the OleDbDataAdapter and 'ds' is the dataset

The complete Block of code is as follows:

string strConn;
OleDbConnection conn ;
OleDbDataAdapter da;

strConn = "Provider=MS Remote;"+"Remote Server=//ind-spz4dxp612/
trial;" + " Remote Provider=Microsoft.Jet.OLEDB.4.0;"+"Data
Source="+@"d:/trial/try1.csv"+";"+"Extended
Properties='text;HDR=Yes;FMT=Delimited'";

conn = new OleDbConnection(strConn);
da = new OleDbDataAdapter("SELECT * FROM [TRY1.CSV]",conn);
da.Fill(ds);========== This Is The line which gives this error.

Your help and inputs will be appreciated.
Thanks.

4. fill some tables is dataset with cached data ? - ADO.Net

5. Problem with wrong data in dataset using SQLDataAdapter.fill

We are experiencing an intermittent problem with our ASP.NET
application.  When using the SQLDataAdapter to fill a dataset, the
dataset is sometimes being filled with the wrong data.  It appears to
be data from different threads.  For example, when retrieving a product
information for the product list page, the dataset that was returned
was a customer address that would have been requested from a different
page in the site.  In this example, table[0] in the dataset should have
contained 4 columns: R.to_oid, P.IsActive, P.ProductID, R.SortOrder
Instead, table[0] in the dataset returned from GetDataSet contained 27
columns of customer address data.  (I have included the code for the
given example below.)  These errors are thrown from many different
pages on the site, and the wrong data that is returned is also from
many different pages of the site. When the problem occurs it will occur
on only one of the server, and will last anywhere from 10 minutes to an
hour or so.  When it occurs, not every dataset is affected, but by
clicking a few links through the site, you can see the error.  You can
click on a product and get an error, go back and click on the same
link, and not get an error.  It's very sporadic.  It does eventually go
away by itself, or we can get the behavior to stop by doing an IISreset
on the affected server.  Does anyone have any insight?

Thanks,
Loralea Seale
INS, Consultant


Environment:
2 load balanced web servers, Win2003, .NET Framework 1.1, no SP
2 SQL Servers, active-passive cluster


Page code behind:

DataSvc.clsDataAccess oData = new
DataSvc.clsDataAccess(g.Const.cAPPLICATION_DatabaseKey);
string sSqlStmt =
string.Format(g.Const.cSQL_RetrieveProductRelationships, sProduct,
"Design");

DataSet oDs = oData.GetDataSet(sSqlStmt, g.Const.cTABLE_Default);

foreach (DataRow oRelationship in oDs.Tables[0].Rows)
{
	sDesign = oRelationship["ProductID"].ToString();     //<<<throws error
here, System.Data.DataRowView does not contain a property with the name
ProductID.

	...

}


g.Const.cSQL_RetrieveProductRelationships value:

"SELECT R.to_oid, P.IsActive, P.ProductID, R.SortOrder " +
"FROM Pens_CatalogRelationships R, Pens_CatalogProducts P " +
"WHERE R.from_oid = (SELECT oid From Pens_CatalogProducts WHERE
ProductID ='{0}') " +
"AND R.Name = '{1}' AND R.to_oid = P.oid AND P.IsActive = 1 ORDER BY
R.SortOrder";


DataSvc class code:

using System;
using System.Data;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Specialized;

namespace DataSvc
{
	/// <summary>
	/// Class clsDataAccess - Contains code for database access and
processing.
	/// </summary>
	public class clsDataAccess
	{
		// Private variables._
		string              _connstring;
		bool                _connected  = false;
		NameValueCollection _configs    = (NameValueCollection)
HttpContext.GetAppConfig("appSettings");
		SqlConnection       _connection = new SqlConnection();

		/// <summary>
		/// clsDataAccess - Initializes class.
		/// </summary>
		public clsDataAccess()
		{
			_connected = false;
		}

		/// <summary>
		/// clsDataAccess - Sets up database connection based on given
connection string.
		/// </summary>
		/// <param name="ConnectionString">Database connection
string.</param>
		public clsDataAccess(string ConnectionString)
		{
			//configuration key exists, open database connection
			if (_configs[ConnectionString] != null)
			{
				_connstring = (string) _configs[ConnectionString];
				_connection = new SqlConnection(_connstring);
				_connected  = true;
			}
			else
			{
				//invalid configuration key name, throw error
				ArgumentOutOfRangeException e = new ArgumentOutOfRangeException();
				throw(e);
			}
		}

		/// <summary>
		/// ~clsDataAccess - Closes database connection.
		/// </summary>
		~clsDataAccess()
		{
			try
			{
				_connection.Close();
			}
			catch {}
		}

		/// <summary>
		/// ExecuteSql - Executes a SQL statement.
		/// </summary>
		/// <param name="Sql">SQL statement to be processed.</param>
		/// <returns>Number of rows affected.</returns>
		public int ExecuteSql(string Sql)
		{
			int rc = 0;
			if (_connected)
			{
				SqlCommand sc = new SqlCommand(Sql,_connection);
				sc.Connection.Open();
				rc = sc.ExecuteNonQuery();
				sc.Connection.Close();
			}
			return rc;
		}

		/// <summary>
		/// GetDataSet - Executes a given SQL statement and returns the
results.
		/// </summary>
		/// <param name="sqlStmt">SQL statement to be processed.</param>
		/// <param name="tableName">Name of table to be labelled for return
results set.</param>
		/// <returns></returns>
		public DataSet GetDataSet(string sqlStmt, string tableName)
		{
			if (_connected == false)
				return null;

			DataSet ds  = new DataSet();

			try
			{
				_connection.Open();
				SqlDataAdapter sda = new SqlDataAdapter(sqlStmt, _connection);

				sda.Fill(ds, tableName);
				_connection.Close();
			}
			catch (Exception ex)
			{
				Log.additionalInfo.Clear();
				Log.additionalInfo.Add("clsDataAccess.cs", "GetDataSet");
				Log.Write(ex);
			}
			finally {
				try {
					if (_connection != null && _connection.State !=
ConnectionState.Closed)
						_connection.Close();
				}catch {}
			}

			return ds;
		}
	}   

}

6. Data Access Application Block v3.0: How to fill DataSet with multi tables - ADO.Net

7. Typed Dataset Not Loading Data On Fill.

Hi All,

I've get a typed dataset that is generated by VS.Net 2003 and it's not
filling some of the tables.  The table mapping are all correct, it just
doesn't fill 1 or 7 tables.

The OnFill does not generate any errors.

I need more info on what is going wrong, anyone got ideas on how to get more
info?

Bruce


8. How To Fill Strong DataSet DateTime Column With yyyyMMDD Data Valu - ADO.Net