|
hi,
first create a command object and then exectue the query i.e. select count(*) statement.
when executing the command object use the executescalar method and equate the result to an integer value.
the sample code:
sqlCommand cmd = new SqlCommand();
cmd.commandtype = commandtype.text
//assign your query to the command here
int count = cmd.executescalar()
....
carry on with your rest of the code, hope this helps.
Gautham
|
|
|
|
|
Thanx for your replay, but it shows me this error:
Error 1 Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)
I changed it, but still I get this exception:
Exception Details: System.InvalidOperationException: <br />
ExecuteScalar: Connection property has not been initialized.<br />
<br />
Source Error:<br />
<br />
Line 52: cmd.CommandText="SELECT count(paperID) FROM Papers WHERE (paperID="+paperID+")";<br />
Line 53:
Line 54: int count=(int) cmd.ExecuteScalar();<br />
thanx
|
|
|
|
|
Let me know is paperID is ur parameter? If yes then when u r going to select then pass this parameter as well
int selectedNum = SqlDataSource1.select(paperID);
hope this will help u
Regards, Arslan Ilyas
|
|
|
|
|
Hi, the following code is taken from a tutorial on reading blobs by Ganegoda.
Private Sub CreateImage(ByVal id As String)<br />
<br />
Dim _con As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("DB"))<br />
<br />
Try<br />
_con.Open()<br />
Dim _cmd As SqlCommand = _con.CreateCommand()<br />
_cmd.CommandText = "select logo from" + " pub_info where pub_id='" + id + "'"<br />
Dim _buf As Byte() = CByte(_cmd.ExecuteScalar())<br />
Response.ContentType = "image/gif"<br />
Response.BinaryWrite(_buf)<br />
Catch<br />
Finally<br />
_con.Close()<br />
End Try<br />
End Sub
I am new to vb.net and not very familiar with it. I have 2 questions regarding the code above.
1) Why is there a plus sign before and after id in the line where pub_id='" + id + "'" ?
2) From reading the MSDN, _con.CreateCommand() is supposed to create a connection and return a SqlCommand object associated with the current connection. However I'm still not clear as to what that means. Is it the same as the following?
<br />
Dim _cmd As SqlCommand <br />
Dim Filter as String<br />
Filter = "select logo from" + " pub_info where pub_id='" + id + "'"<br />
_cmd = New SqlCommand(Filter, _con) <br />
Thanks in advance for your help.
-- modified at 4:04 Sunday 15th July, 2007
|
|
|
|
|
ASPnoob wrote: 1) Why is there a plus sign before and after id in the line where pub_id='" + id + "'"?
The + operator is used for addition. When used on strings it means that the strings are concatenated.
ASPnoob wrote: 2) From reading the MSDN, _con.CreateCommand() is supposed to create a connection and return a SqlCommand object associated with the current connection. However I'm still not clear as to what that means.
This code:
Dim _cmd As SqlCommand = _con.CreateCommand()
is equivalent to:
Dim _cmd As New SqlCommand(Nothing, _con)
---
single minded; short sighted; long gone;
|
|
|
|
|
ASPnoob wrote: Filter = "select logo from" + " pub_info where pub_id='" + id + "'"
Have to be careful with this code. It is prone to SQL Injection attacks. Look at this article[^] on preventing SQL injection attacks.
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
|
|
|
|
|
Hi Ganegoda,
The + sign is nothing but used for string concatenation. have u noticed that 'id' is we are passing with the string where pub_id=....., thats why we need to concatenate with plus signs on both sides.
Take care.
Please let me know if you have still doubts.........
Best Regards,
Mohammed Hameed.
Be a good professional who shares programming secrets with others.
|
|
|
|
|
Hi.I host one page,i done that page in C#[ASP.Net].i just add one Label and given Text as "Welcome" after hosting this page when i open this page the page is blank,when i take the source of the page am getting Label1.text=Welcome what is the problem.should i set any property.
|
|
|
|
|
Are you sure it is not invisible? :->
|
|
|
|
|
It sounds like you have put some code in the wrong place. The server code runs on the server and is not visible in the html source, so somehow you have put the code somewhere where it's not server code any more.
I can't tell you any more than that without seeing any code.
---
single minded; short sighted; long gone;
|
|
|
|
|
The Following code is SourceCode [ HTML Code ].In the HTML Code can see one Label Control and the Text is Welcome,even that also is not displaying after hosting this page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Photos.aspx.cs" Inherits="Photos" EnableSessionState="False" %>
<title>Untitled Page
<asp:label id="Label1" runat="server" style="z-index: 100; left: 188px; position: absolute;
top: 46px" text="Welcome" width="237px" backcolor="#0066FF" forecolor="White">
<asp:datagrid id="dgPhotos" runat="server" style="z-index: 102; left: 168px; position: absolute;
top: 79px" cellspacing="20" gridlines="None" onitemcreated="dgPhotos_ItemCreated">
<columns>
<asp:templatecolumn>
<itemtemplate>
<itemstyle font-bold="False" font-italic="False" font-overline="False" font-strikeout="False"
="" font-underline="False" horizontalalign="Center" verticalalign="Middle">
|
The Page Load Event as follows
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable("Photos");
dt.Columns.Add("Photos", Type.GetType("System.String"));
foreach (string Files in Directory.GetFiles(Request.MapPath("Photos"), "*.jpg"))
{
dt.Rows.Add(Files);
}
ds.Tables.Add(dt);
this.dgPhotos.DataSource = ds;
this.dgPhotos.DataBind();
}
}
|
|
|
|
|
Half of you code is missing or unreadable. Use the "Ignore HTML" option when you are posting markup code.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi Guffa,
i am using the following code to export dataset data to excel in asp.net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
Dim con As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\Administrator\Desktop\a.mdb")
con.Open()
Dim ds As New Data.DataSet
Dim ad As New OleDbDataAdapter("select * from a", con)
ad.Fill(ds)
GridView1.DataSource = ds
GridView1.DataBind()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls")
Response.Charset = ""
'// If you want the option to open the Excel file without saving then
'// comment out the line below
'// Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter()
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
GridView1.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
End Sub
there is occuring an error
Control 'GridView1' of type 'GridView' must be placed inside a form tag with runat=server.
but the control is under the form tag with runat server
Sonia Gupta
Soniagupta1@yahoo.co.in
Yahoo messengerId-soniagupta1
Love is Friendship and Friendship is Love....
|
|
|
|
|
Hi Sonia.
Don't post questions in totally unrelated threads. Start a new thread, otherwise hardly anyone will see your question.
---
single minded; short sighted; long gone;
|
|
|
|
|
SORRY.......
Sonia Gupta
Soniagupta1@yahoo.co.in
Yahoo messengerId-soniagupta1
Love is Friendship and Friendship is Love....
|
|
|
|
|
I am just starting out with programming asp.net and have purchased an asp.net webhosting wiht DailyRazor.com.
I then tried to build a simple webpage (in C# as this is the language I am familiar with) with Visual Studio 2005, which gave me 2 files:
Default.aspx
Default.aspx.cs
(when i run 'Run without debugging' in VS, it seems to work OK on my local webserver)
But when I uploaded both these files to my 'httpdocs' folder on the webhost folder
and I try to run file Default.aspx, I get the error:
"Could not load type '_Default'."
But if I remove the 'Inherits="_Default"' part, I get error:
"The 'CodeFile' attribute is not supported by the 'page' directive."
This is the code contained in default.aspx:
<br />
<br />
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<br />
<html xmlns="http://www.w3.org/1999/xhtml" ><br />
<head runat="server"><br />
<title>Untitled Page</title><br />
</head><br />
<body><br />
<form id="form1" runat="server"><br />
<div><br />
Hello World - my first C# webpage !!<br />
</div><br />
</form><br />
</body><br />
</html><br />
<br />
And the code file:
<br />
using System;<br />
using System.Data;<br />
using System.Configuration;<br />
using System.Web;<br />
using System.Web.Security;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
using System.Web.UI.WebControls.WebParts;<br />
using System.Web.UI.HtmlControls;<br />
<br />
public partial class _Default : System.Web.UI.Page <br />
{<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
<br />
If anyone knows of a good tutorial which shows how to create a simple webpage in VS2005 (language C#, for the code-behind anyway) and then upload it to a webserver (though I thought this would have been the same as whatever works on the local server) that would be a great help.
Many thanks,
Gerry
asp.net newbie
|
|
|
|
|
are u using .net 2003 or .net 2005?
Best Regards
3ala2
|
|
|
|
|
Well - seeing that he said he was using Visual Studio 2005, it's a fair bet (read he must be) that he's using .NET 2. (There isn't a .Net 2003 or .Net 2005).
I also fail to see what relevance this has to his problem. That's like asking if he's developed this on a Dell or an Acer - totally irrelevant.
|
|
|
|
|
Sometimes low knowledge and some attitude would cause u problems Pete
When u know nothing about configuration don't talk about configuration
And by the way, my McAfee needed a patch to run on my Dell while it didn't need that patch to run on my other PC!
Best Regards
3ala2
|
|
|
|
|
Bonjour Gerry
How did you upload your site?
Select Build > Publish Web Site. You will find that you can select a site to create a precompiled uploadable version of the site. When you build the site, you have a DLL that contains the code that you need. Publish this version to your website instead.
|
|
|
|
|
Hi gvanto,
Some hosting servers have index page as default or default page as default.
so you better to try with index page by giving redirect to that default page.
I hope this works fine.check u r hosting server once and do this.
Regards,
Niranjan
|
|
|
|
|
Hi,
Is there a way of extending the ContentPlaceHolder Class and using the extended class in the MasterPage?? If so, would I have to implement my own asp:Content control and hook it up with my custom asp:ContentPlaceHolder control??
Please can someone explain this concept to me?
Regards,
ma se
|
|
|
|
|
Perhaps you can, but why?
Perhaps you should explain what it is that you are trying to accomplish, instead of asking things about the way that you think that it's done.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hello anyone knows how to convert http to https. i need one example does any one know anything about this .I already register versign but i need to know how to put the lock in the sensitive information.
Can any one give me one example .Thanks In advance
|
|
|
|
|
aditya.net wrote: convert http to https
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|