tomcalef
asked on
Pull value to textbox from sqldatasource, Asp.net C#
I am trying to pull a date value from a sqldatasource that only selects 1 row with a few columns. The name of the date column is In_Date. It would be the first row third column. I am trying to pull the value so I can use it for a calculation, so the goal is to get it to a label or textbox. I'm not sure what else I can post to explain, so If you need more information please ask. The aplication is a web asp.net page in c#.
ASKER
I'm getting an error that says " 'system.data.dataview' does not contain a definition for 'Rows'
I have replaced datasource with sqldatasource6 (the data source i'm trying to use) and everything else was left the same. Any ideas or do you need more information?
I have replaced datasource with sqldatasource6 (the data source i'm trying to use) and everything else was left the same. Any ideas or do you need more information?
TextBox1.Text = objDs.Tables[0].Rows[0]["I n_Date"] ;
where objDs is dataset and assumes that first table first row contains data
Regards
Renju
where objDs is dataset and assumes that first table first row contains data
Regards
Renju
in traxion: solution i thk instead of dataview' it is dtData
TextBox1.Text = dtData .Rows(0)("In_Date");
Regards
Renju
TextBox1.Text = dtData .Rows(0)("In_Date");
Regards
Renju
Yes, I'm sorry. You're populating the DataTable from the DataView so it should be:
Textbox1.Text = dtData.Rows(0)("In_Date");
Thanks Renju
Textbox1.Text = dtData.Rows(0)("In_Date");
Thanks Renju
ASKER
The error message now is system.data.datatable.rows is a property but used like a method.
ASKER
This is the code thus far:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments( );
DataView objView = (DataView) SqlDataSource6.Select(dsAr gs);
DataTable dtData = objView.ToTable();
TextBox1.Text = dtData.Rows[0]["In_Date"]. ToString() ;
When I press the button that runs this action I get a box that highlights
DataTable dtData = objView.ToTable();
and a box comes up saying NullReferenceException was unhandled by usercode
it suggests adding the new keyword but I have no idea where.
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments(
DataView objView = (DataView) SqlDataSource6.Select(dsAr
DataTable dtData = objView.ToTable();
TextBox1.Text = dtData.Rows[0]["In_Date"].
When I press the button that runs this action I get a box that highlights
DataTable dtData = objView.ToTable();
and a box comes up saying NullReferenceException was unhandled by usercode
it suggests adding the new keyword but I have no idea where.
hmm...
Let's try it without the direct cast:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments( );
DataView objView = SqlDataSource6.Select(dsAr gs);
DataTable dtData = objView.ToTable();
TextBox1.Text = dtData.Rows(0)("In_Date"). ToString() ;
Let's try it without the direct cast:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments(
DataView objView = SqlDataSource6.Select(dsAr
DataTable dtData = objView.ToTable();
TextBox1.Text = dtData.Rows(0)("In_Date").
You could also utilize a property of the SelectArguments to make sure something is set, like the StartRowIndex:
dsArgs.StartRowIndex = 0
so the code would look like this:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments( );
dsArgs.StartRowIndex = 0;
DataView objView = SqlDataSource6.Select(dsAr gs);
DataTable dtData = objView.ToTable();
TextBox1.Text = dtData.Rows(0)("In_Date"). ToString() ;
dsArgs.StartRowIndex = 0
so the code would look like this:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments(
dsArgs.StartRowIndex = 0;
DataView objView = SqlDataSource6.Select(dsAr
DataTable dtData = objView.ToTable();
TextBox1.Text = dtData.Rows(0)("In_Date").
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It doesn't seem to like that either.
Code:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments( );
DataView objView = SqlDataSource6.Select(dsAr gs);
DataTable dtData = objView.ToTable();
Label1.Text = dtData.Rows[0]["In_Date"]. ToString() ;
Error
"Error 1 Cannot implicitly convert type 'System.Collections.IEnume rable' to 'System.Data.DataView'. An explicit conversion exists (are you missing a cast?)"
Code:
DataSourceSelectArguments dsArgs = new DataSourceSelectArguments(
DataView objView = SqlDataSource6.Select(dsAr
DataTable dtData = objView.ToTable();
Label1.Text = dtData.Rows[0]["In_Date"].
Error
"Error 1 Cannot implicitly convert type 'System.Collections.IEnume
try the very last example.
ASKER
I was getting very frustrated by this till I found an issue with my datasource, Sorry for the hold up. My source wasn't selecting the right data and causing an empty return. Your solution was on the money traxion. Thank you
:D You're welcome. It was frustrating me as well! I didn't have a test platform and I was converting from my VB code to C# so I was worried the symantics weren't correct. Glad you got it working!
Thanks,
Dustin
Thanks,
Dustin
DataView objView = (DataView)dataSource.Selec
DataTable dtData = objView.ToTable();
Then, TextBox1.Text = objView.Rows(0)("In_Date")