Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

ValueType Mistmatch when opening an SPSite

  Asked By: Devan    Date: May 02    Category: Sharepoint    Views: 1104

I'm writing a web part to search through a Sharepoint list. I'm using
Sharepoint 2003 with WSS 2.0. I'm developing the web part with Visual
Studio 2005. The code is as follows:

SPSite mySite = new SPSite("https://www.myintranet.com");
SPWeb web = mySite.OpenWeb();
SPList myList = web.Lists["My List"];
SPQuery query = new SPQuery(myList.Views["Full View"]);

string caml = "<Where><Eq><FieldRef Name='Last Name'/>"
+"<Value Type='Text'>Smith</Value></Eq></Where>";

query.Query = caml;
SPListItemCollection results = myList.GetItems(query);
SPListItem employee = (SPListItem)results[0];
txtResult.Text = (employee["Last Name"].ToString());

I'm running the code from the server that hosts www.myintranet.com.
This code is called when I click in a button that resides inside a
Web Part Zone.

When I run it, I get the following error:

!"ValueType mismatch"
Exception Details: System.BadImageFormatException: !"ValueType

The stack trace is:

[BadImageFormatException: !"ValueType mismatch"]
Microsoft.SharePoint.SPSite.a(String A_0, SPVirtualServer A_1, a
A_2, Int32 A_3) +0
Microsoft.SharePoint.SPSite..ctor(String strUrl) +171
searchLists_ascx.btnSearch_Click(Object sender, EventArgs e) +37
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +81
eventArgument) +219
aisePostBackEvent(String eventArgument) +12
sourceControl, String eventArgument) +18
postData) +38
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

What am I doing wrong? This is my first Web Part so any help will be



5 Answers Found

Answer #1    Answered By: Leif Cardenas     Answered On: May 02

Found the issue. It seems that this is because doesn't support Whidbey
yet, NET Framework 2.0. If anyone knows a work around please update
this posting.

Answer #2    Answered By: Jasper Hatfield     Answered On: May 02

Make all your SPPT Sites specifically use .NET 1.1 Framework? I
understand there is a new tab in the IIS properties window to do this. I
haven't seen it yet.

Alternatively, you could wait until SPPT SP2 to install .NET 2.0
Framework when it is supported.

Answer #3    Answered By: Rashawn Hopper     Answered On: May 02

What kind of a list  is "Full View"?

Are you certain that the field is called "Last Name" with a space? What
is the internal name compared to the display name?

Which statement is the code failing on?

Here is a simple query that I use all the time (notice how I've escaped
our the double quotes):

System.Text.StringBuilder queryString = new
queryString.Append(" <And>");
queryString.Append(" <Eq>");
queryString.Append(" <FieldRef Name=\"Status\" />");
queryString.Append(" <Value
queryString.Append(" </Eq>");
queryString.Append(" <Eq>");
queryString.Append(" <FieldRef Name=\"Modified\" />");
queryString.Append(" <Value Type=\"DateTime\"><Today
queryString.Append(" </Eq>");
queryString.Append(" </And>");

SPQuery query = new SPQuery();
query.Query = queryString.ToString();

//Query the list
items = list.GetItems(query);

Answer #4    Answered By: Horace Coffey     Answered On: May 02

I will test your query. I think the problem
was that I was using VS.NET 05 so will try with 03.

The "Full View" refer to a view of the list. I have not test this but
saw it in the specifications and wanted to see how it worked.

Answer #5    Answered By: Rigoberto Beard     Answered On: May 02

the query is working fine, the problem was because I was using VS.NET 05 and because I was referring to the field "Last Name" as is, instead of "Last_x0020_Name".

One last questions: I'm displaying the information in a grid, but when I render the datagrid, I also get an extra column with the list  item ID. This is the code:

//I define a class variable DataGrid dgrid before this

SPSite mysite = new SPSite("http://localhost");

SPWeb web  = mysite.OpenWeb();

SPList mylist = web.List["My List"];

SPQuery query = new SPQuery();

query.ViewFields = "<FieldRef Name='First_x0020_Name'/><FieldRef Name='Last_x0020_Name'/><FieldRef Name='Phone_x0020_Number'/>";

query.Query = "<Where><BeginsWith><FieldRef Name='First_x0020_Name'/><ValueType='Text'>"+text+"</Value></BeginsWith></Where>";

SPListItemCollection items = mylist.GetItems(query);

dgrid = new DataGrid();

dgrid.DataSource = items.GetDataTable();




// then I refer to this control when I render the web part...


This produces a table that looks like this

First_x0020_Name Last_x0020_Name Phone_x0020_Number ID
John Dwyne *** *** *** 99
John E. Smith *** *** *** 54

I don't know why I'm getting the ID and also, how can I do so the title doesn't display the hex number. Do you know how?

Didn't find what you were looking for? Find more on ValueType Mistmatch when opening an SPSite Or get search suggestion and latest updates.