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
mismatch"
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
System.Web.UI.WebControls.Button.RaisePostBackEvent(String
eventArgument) +219
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.R
aisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData) +38
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+4430
What am I doing wrong? This is my first Web Part so any help will be
appreciated.