|
you can use substring in your sql statement / C# code.
i.e.
SQL : select substring(para,1,10) from mytable where paraID = 1234
C# : short_para = para.Substring(0,10);
also just check the lenght > 10 of the string before this so that you will not get the error like. index is out of the string...or something...
and please (dont take this in wrong way) first try the google or msdn, if you dont get the answers then post in the forum. because there are soo many post in the different forums, for the indian developer posting basic questions (questions that can be found using google ot msdn). (I just read one in the Lounge)
may be this is the reason nobody is replying you, or i may also get a reply that dont answer such basic questions.
there is one article on code project for how use google search. please refer to that.
thanks...
|
|
|
|
|
I am reading some data from the database, but its giving System.InvalidOperationException:
my code is as follows :
LoadInfo l = new LoadInfo();
l.LoadFromSQL(Session["username"].ToString());
the class LoadInfo has the member function LoadFromSQL as follows,
public void LoadFromSQL(string username)
{
SqlDataReader reader = null;
reader = SqlMember.ExecuteReader("SELECT UserId FROM Members WHERE UserName=@username", username);
m.LoadFromReader(reader);
}
the SqlMember class has the static member function ExecuteReader as following:
static public SqlDataReader ExecuteReader(string qs,string username)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand(qs, conn);
cmd.Parameters.Add(new SqlParameter ("@username","a"));
conn.Open();
if (cmd.ExecuteScalar() == null)
{
int i;
i = 0;
}
return cmd.ExecuteReader();
}
the LoadFromReader member function of SqlMember class is as follows:
public void LoadFromReader(SqlDataReader reader)
{
this.UserId = (int)reader["UserId"];
this.FirstName = (string)reader["FirstName"];
this.LastName = (string)reader["LastName"];
this.CityId = (int)reader["CityId"];
this.CountryId = (int)reader["CountryId"];
this.Mood = (byte)reader["Mood"];
}
The exception is occurring in the above function, while reading the data from the reader
this.UserId = (int)reader["UserId"];
if this line is commented (//) the exception occurs in the next line.
Error:
Invalid attempt to read when no data is present.
The username provided by the session object is available in the database.
Please help me to solve this problem.
Is there any way to know, if the ExecuteReader returned any values ?
Apurv
|
|
|
|
|
I think it is showing you the error because you forgot to call Read()
also your query returns only UserID and you are reading whole row.
so change the
Select UserID FROM Members WHERE UserName=@username to
Select UserID,FirstName,LastName,CityId,CountryId,Mood FROM Members WHERE UserName=@username
in the LoadFromReader()
public void LoadFromReader(SqlDataReader reader)
{
if(reader.Read())
{
this.UserId = (int)reader["UserId"];
this.FirstName = (string)reader["FirstName"];
this.LastName = (string)reader["LastName"];
this.CityId = (int)reader["CityId"];
this.CountryId = (int)reader["CountryId"];
this.Mood = (byte)reader["Mood"];
}
else
}
also change the ExecuteScalar() to ExecuteReader()
because now you are getting more than one values.
|
|
|
|
|
thanx ....
will try with the changes ...
Apurv
|
|
|
|
|
Its working thanks .....
Apurv
|
|
|
|
|
Hi All,
I am developing a WebApplication using ASP.NET and C#.
there is a exception occurs when i call for a XmlWeb Service --Web Method.
This is the code.
try{
DataXML service=new DataXML();
service.Timeout = 10 * 60 * 1000;
object[] results = service.GetProductionData();
}catch(Exception ex)
{
str=ex.Message;
}
Here we have to wait around 100 seconds to get the response. But before that there is exception occurs and the error message says
'The underlying connection was closed: The connection was closed unexpectedly
So the client side returns a exception before results come. why is that??
can any one help on this?
Thanks in advance..
|
|
|
|
|
It is impossible to answer the way you have posted your question. Why don't you place a debugger in the method GetProductionData and see if there is a problem in that method or not.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Hi,
I have debugged the code. but I can not find a error. while I am debugging the XML Webservice method,client side displaying the error message.
why is that? Is it like timeout error?
|
|
|
|
|
Post the code of your webservice method.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
I use the ajax.net stuff a lot, but some of its features are not as nice as those found in Scriptaculous/Prototype. However, I have found that if you try and use a mixture of both on a site, it can cause bugs, so I had to ditch the Scriptaculous bits and just use ajax.net.
Has anyone used any other frameworks along side ajax.net without problems? Just wondering if there is a more compatible one out there?
Words fade as the meanings change, but somehow, it don't bother me.
|
|
|
|
|
Not specifically with ASP.NET Ajax, but I have had problems - mostly stemming from the fact that every man and his dog seems to have overridden the $ character - we did to do document.getElementById, but scriptaculous had also grabbed it...
C# has already designed away most of the tedium of C++.
|
|
|
|
|
aspnet_regiis.exe -ga "Network service"
The above command grants "Network service" access to the IIS metabase and other directoriesused by ASP.NET.
Is there any way to do using "Security Identifieir"SID[^] instead of user name, actually it is useful in Localized OS.
Thanks,
Mushq
|
|
|
|
|
Hi.
I have todevelope a web site that it uses ssl.
Providing ssl is with customer.
Do I do any special work in my programming?
or I do my traditional work (design & programming) and finally up it such previous?
Best wishes
|
|
|
|
|
Well, SSL has nothing to with programming, it is related with deployment.
But, if you are sending links somewhere in application than keep in mind to select the protocol using code rather than hardcoding(http or https)
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Manas Bhardwaj wrote: if you are sending links somewhere in application than keep in mind to select the protocol using code rather than hardcoding(http or https)
I didn't underestand it! can explain it, please?
Best wishes
|
|
|
|
|
Just make your site as normal. You don't need to do anything in programming for deploying with SSL.
The pages which you want to be on SSL should be properly called like https://yourdomain/yourpage.aspx
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
|
You don't need to add any extra code for a SSL site. You should get SSL from a provider, install on your server and request page using HTTPS protocol. It's the secure HTTP connection.
|
|
|
|
|
You should first have an SSL certificate installed on your domain.
Then do something like this depending on your requirements:
Write a redirect script, that redirects all requests to your website to https://
<br />
<%EnableSessionState=False<br />
host = Request.ServerVariables("HTTP_HOST")<br />
<br />
if host = "your-domain.com" or host = "www.your-domain.com" then<br />
response.redirect("https://www.your-domain.com/index.html")<br />
<br />
else<br />
response.redirect("https://www.your-domain.com/error.html")<br />
<br />
end if<br />
%><br />
This script needs to be named default.asp and placed in the folder your domain is pointing to.
|
|
|
|
|
Hey guys, whats happening ?
I'm using a ObjectDataSource and link it to a class which contains a method for selecting from database i try to configure the data source but I cannot choose a business object, the combo box in the wizard is empty !!! my class is in App_Code folder so automatically it must be loaded in the combo bod in the configuration wizard !
Thanx
Mr.K
|
|
|
|
|
Your question is not clear. Please always make it clear. What is your problem and what you want to do.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
I'm using an Object Data source ! I have a class in my APP_Code folder which includes methods for inserting data. I tried to use objectdatasourse's wizard but it doesn't read those classes in my app_code folder !
Mr.K
|
|
|
|
|
Hi
How would I select part of a string value.
For example if I had a string which said
"Room ID = jghdu"
and I wanted to select all text after '=', how would I go about doing that?
thanks!
|
|
|
|
|
string abc = yourString.SubString(yourString.indexOf("="));
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
just a addition
string abc = yourString.Substring(yourString.IndexOf("="));
abc = abc.Remove(0, 1);
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|