Hello,
I have a General question, does anyone know a better way to get data from a SQLDatasource that can be hidden from view? I have a DataView right now and to do anything on it it must be visible and I cant seem to make it disappear. Is there a better way to count rows / Access data without a dataview object? I am using Ajax Update panel to look at the data if that matters.
Thanks!
Not sure what you are asking here... the DataView isn't a "visible" control (http://msdn2.microsoft.com/en-us/library/system.data.dataview.aspx). Did you mean GridView?
What problem are you trying to solve?
-Damien
I have the following code:
Protected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Button1.Click, Panel5.DataBinding If Me.IsPostBack()Then
Dim testvalAs Integer =Me.DetailsView1.Rows.Count()
If testval > 0Then
Label1.Visible =True
Label1.Text ="ERROR: The Project Name you have selected is already in use on this team."
Me.Panel5.Height = 24
Me.Panel5.Width = 590
Else
Me.Panel5.Height = 0
Me.Panel5.Width = 0
Label1.Visible =False
End If
End If
End Sub
-----
Basically, when I made the panel, or the Details View hidden it does not work because it always has a count of 0. The details view has to be VISABLE and it shows on my page. What I want to do is be able to find out how many rows (or get a data item) using another way to do the same thing as the above without showing the DATA on the screen to the user. I have databound all of the objects and it works but it just looks ugly. But am having a lot of trouble because its in an update panel which is hidden until this check goes... so I am not quite sure what else I can use to do the above. Any Suggestions? I am new to ASP.NET I am more used to the datasources of the VB.Net where I had a binding datasource that I could access without having to display it on the page. I have not beenable to find that for ASP.NET yet.
Thanks!
Ok, DetailsView, not DataView :) What you want to use is the DataView.
Take a look here:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=228386&SiteID=1
Specifically the code:
string connectionString = "...Northwind Connection String...";
string selectSql = "SELECT [CategoryID], [CategoryName] FROM [Categories]";
DataSourceSelectArguments args = new DataSourceSelectArguments();
SqlDataSource dataSource = new SqlDataSource(connectionString, selectSql);
DataView view = (DataView)dataSource.Select(args);
You can then use DataView.Count to get the total records, or you can filter the results.
Hope this helps...
-Damien
Hi,
I was able to convert everything above into Visual Basic code but something is giving me the error on line 7:
System.Data.SqlClient.SqlException was unhandled by user code
Class=15
ErrorCode=-2146232060
LineNumber=1
Message="Incorrect syntax near the keyword 'AND'."
Number=156
Procedure=""
Server="SQL112.viux.com"
Source=".Net SqlClient Data Provider"
The code I used is:
1Dim connectionStringAs String ="Data Source=SQL112.viux.com;Initial Catalog=StartPlan;Persist Security Info=True;User ID=user;Password=password"2Dim selectSqlAs String ="SELECT ProjectName FROM Projects WHERE (ProjectName = " +Me.TextBox1.Text.ToString() +" AND (TeamId = " +Me.DropDownList1.SelectedValue.ToString() +") GROUP BY ProjectName"34Dim argsAs DataSourceSelectArguments =New DataSourceSelectArguments()56Dim dataSourceAs SqlDataSource =New SqlDataSource(connectionString, selectSql)7Dim view6As Data.DataView = dataSource.Select(args)89If Me.IsPostBack()Then10 Dim testvalAs Integer = view6.Table.Rows.Count()
Anyone know what is up?
Thanks!
Exactly what it says "Incorrect syntax near the keyword 'AND'"
It should be ") AND (TeamId = " +Me.DropDownList1.SelectedValue.ToString() +") GROUP BY ProjectName"
-Damien
AWESOME! Actually I was missing some extra " ' " marks in there as well. But then it worked after that!!!!
Thanks dude!
No comments:
Post a Comment