Showing posts with label guys. Show all posts
Showing posts with label guys. Show all posts

Sunday, March 11, 2012

"Object reference not set to an instance of an object" error

Hi,guys
I met a problem, the error message is "Object reference not set to an instance of an object." ,which indicating the * row has this problem. I really don't understand, please help me!
Bellow is my code:
private void BindTypeData(){
string query = "select * from tblFacilityType";
sqlDataAdapter = new SqlDataAdapter(query,sqlConnection);
ds = new DataSet();
sqlDataAdapter.Fill(ds,"tblFacilityType");
* FacilityDataGrid.DataSource = ds.Tables["tblFacilityType"];
FacilityDataGrid.DataBind();
}
Thanks first!

feiMake sure that sqlConnection and FacilityDataGrid are instantiated somewhere else.|||hi,jason
I've checked, it is there. But i still have the same problem!

public class __FacilityType : System.Web.UI.UserControl
{
protected DataSet ds;
protected SqlConnection sqlConnection;
protected SqlDataAdapter sqlDataAdapter;
protected SqlCommand sqlSelectCommand;
protected SqlCommand sqlInsertCommand;
protected Panel FacilityTypePanel;
protected DataGrid FacilityTypeDataGrid;
protected SqlDataReader reader;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!Page.IsPostBack){
BindTypeData();
}
}
//Todo: bind data for the facility list datagrid
private void BindTypeData(){
string query = "select * from tblFacilityType";
sqlDataAdapter = new SqlDataAdapter(query,sqlConnection);
ds = new DataSet();
sqlDataAdapter.Fill(ds,"tblFacilityType");
FacilityTypeDataGrid.DataSource = ds.Tables["tblFacilityType"];
FacilityTypeDataGrid.DataBind();
}|||Where and how are u instantiating sqlConnection?

Thursday, March 8, 2012

"Network general error"....

Hi Guys,

I have a problem with my application.when i try to run it to a network pc, show me this message "Network general error". But if i run it to simple pc everything ok.

Database is local. SQL Express agent running locally.Also all protocols for sql server is enebled.

Any ideas,,,,

COuld it be that the firewall is enabled or not configured for accessing the computer on this specific port ?

HTH, jens Suessmeyer.

http://www.sqlserver2005.de

Saturday, February 25, 2012

"Certificate not yet valid"

Hi guys,

I'm having this really strange issue with mirroring.

I've followed the instructions on http://msdn2.microsoft.com/en-us/library/ms191140.aspx to the letter, leaving out the witness server part, as I don't have one.

All works OK, but when activating the mirroring on the principal server I get the usual error 1418 error. I fired up SQL Server Profiler to see what was happening, and the following error emerged.

Connection handshake failed. The certificate used by the peer is invalid due to the following reason: Certificate not yet valid. State 104.

Anyone have any ideas?

If you live in the eastern hemisphere the newly created certificate is not yet valid at creation for a number of hours equal with the time difference between you time zone and GMT.
You van specify the certificate start date explictly one day in the past or wait for the numbers of hours specified (they are probably valid by now)

HTH,
~ Remus|||

Well, I live in GMT, but it works now, so I can only presume something similar was the problem.

Cheers

Thursday, February 16, 2012

<asp:SqlDataSource> generate SQL for GridView?

Hi guys.

Im using a gridview to show some training data on my website which is populated by:

<asp:SqlDataSource ID="ARENATraining" runat="server" ConnectionString="<%$ ConnectionStrings:ARConnection %>"
SelectCommand="SELECT [EventType], [CourseLink], [EventDate], [EventTitle], [EventLocation], [EventWebsite] FROM [qry_FutureEvents] WHERE ([EventPrivate] = @.EventPrivate) ORDER BY [EventDate]">
<SelectParameters>
<asp:Parameter DefaultValue="FALSE" Name="EventPrivate" Type="Boolean" />
</SelectParameters>

So far so good..

However I want to be able to filter the data.

A) Show everything

B) Show individual EventType i.e. Seminar, Training etc etc

Is it possible to generate the Select Command via a function?

(im not using stored procedures for this part of the site, nor really want to at the moment).

Id appreciate any help, otherwise ill be forced to curse and swear and use the good ol repeater and figureing out how to page it!

Cheers guysBig Smile

Well, repeaters work the exact same way as gridviews when it comes to databinding.

In any case, the sqldatasource control does expose its selectcommand property. So really, just programmatically set the property, then call the databind method of the gridview, and you're set.

Another possibility is to generate a SQL statement that uses parameters (like I beleive you're currently doing). Then on the "Selecting" event of the sqldatasource, you can set the parameter like: e.InputParameters["paramName"] = "whatever" (so if your query ends with "where somefield LIKE @.someparam", you can use % to show everything as a wildcard, or specify a parameter.

Another option is to set the parameter declaratively, and bind it to Session or a control or something (when you create the sqldatasource, thats what the parameter part of the wizard is for), but I tend to find that a little annoying to paintain, so I suggest the above methods.

|||

Thanks very much for your help!

I didnt know you could do define SqlDataSource outwith the aspx page.

Incase anyone found this thread trying to do the same thing I found this URL with an example

http://geekswithblogs.net/azamsharp/archive/2005/07/19/47711.aspx

Thanks again Shados!

|||

Sorry guys,

Im having real problems with this still :(

Ive been trawling through google all morning and im not quite getting there.

So far ive came up with

Public Sub AddDataSource()Dim dsAs SqlDataSource =New SqlDataSource() ds.ID ="mySqlSourceControl" Page.Controls.Add(ds) ds.ConnectionString = ConfigurationManager.ConnectionStrings("ARENAConnection").ConnectionString ds.SelectCommand ="SELECT [EventType], [CourseLink], [EventDate], [EventTitle], [EventLocation], [EventWebsite] FROM [qry_FutureEvents] WHERE ([EventPrivate] = @.EventPrivate AND [EventType] = @.EventType) ORDER BY [EventDate]"Dim cpAs Parameter cp =New Parameter("@.EventPrivate", TypeCode.Boolean,"False") cp =New Parameter("@.EventType", TypeCode.String,"Training") ds.SelectParameters.Add(cp)Dim paramAs ControlParameter =New ControlParameterEnd Sub
This leaves me the error:
System.Data.SqlClient.SqlException: Must declare the variable '@.EventPrivate'.
I'm that close i can smell it... 
Have pity someone [:'(]
Cheers 
|||

Sorry for taking so long to reply to you. I just woke up, AND I needed to test this by myself before replying to you. It is actualy much simpler than what you're trying to do.

First, make your SQLDatasource normally (you know, like with the wizard, or manually, etc).

Then all what you have to do is, in the designer, double click on the datasource. This will register the Selecting event. Now, one of the parameters is "e", and it has a member, called "command". This is the readonly property that contains the SqlCommand object. Now, the sqlcommand itself is readonly...however, its methods can still be used!

so you can do this:

e.Command.Parameters.Add(newSqlParameter("@.EventPrivate",false)); //note how it will take objects, so you don't need to specify a type

and you're set. No need to do anything else.

Your issue in your case, is that onload, the grid will try to bind on the datasource, and you didn't set its parameters yet, thus it cannot find them.
If your way had worked, you would have ended up with a datasource that binds twice on every load =P Anyway, so just register the Selecting
event of the datasource: this is called -everytime- the datasource is called. And you can do all the work there, as shown above ^_^

|||

Hi Shados

I really appreciate you taking your time helping me with this, it worked perfectly Big Smile

Sorry i didnt reply sooner, I just moved house and my ISP are being lazy!

It is indeed much simpler!

Thanks again

|||Don't worrie about, most people never even reply once they found their solutions :)