|
I didn't find any mistake in your code, But the way you're using development approach is very BAD.
Just to make a note.
jim haras wrote: while (Reader.Read())
{
books.book_ID = Reader[0].ToString();
books.title = Reader[1].ToString();
books.author = Reader[2].ToString();
books.publisher = Reader[3].ToString();
books.category = Reader[4].ToString();
books.year = Reader[5].ToString();
books.edition = Reader[6].ToString();
books.isbn = Reader[7].ToString();
books.price = Reader[8].ToString();
books.number_of_Copies = Reader[9].ToString();
}
If you want to get all things returned from a query then use SqlDataAdapter will be having less code lines. Fill the results in a DataTable .
As of you're passing BookID then I don't think there's chance of fetching multiple rows from DB, If you've kept BookID Unique or PrimaryKey .
Most of the things were already suggested by PIEBALDconsult, Add mine this to it.
|
|
|
|
|
thanks for the replies guys! maybe i didn't explain it properly. the problem is not in the code that i posted. despite its structure, it works fine. the problem i am facing is in the web page. i put a textbox that will be filled with the book id ( or the title or the author it doesn't matter) and a grid view ( or a bunch of text boxes each assigned to show a different collumn of the books database) that will display the search results from the database using the web method in the web service ( the one i posted earlier). i can not make it display the results
|
|
|
|
|
Let me make it easier for you to understand what i want to do. in my web page i use a dropdown list which contains the customer id column of the customer data table as input and i try to call the web service that i posted above. i want the array that the web service returns to be displayed in a grid view( or any other way for that matter but i prefer the grid view ). this is what i wrote:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Array getinfo = new Array[6];
try
{
localhost.WebService1 myserv1 = new localhost.WebService1();
getinfo = myserv1.GetCustomer(DropDownList1.Text);
GridView1.DataSource = getinfo;
GridView1.DataBind();
}
catch (Exception ex)
{
Label8.Text = ("Unable to find user because" + ex.Message);
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
and it returns nothing.Thanks in advance
|
|
|
|
|
Can anyone explain this line in plain english (I am learning).
var userCallback = e.UserState as Action<bool>
I understand how to call a typical invoke method on an action but how is e.UserState convertable to an Action<bool>? From what i have seen in object browser e.UserState is just calling a property.
When i right click on the property and select get definition this is the property it is referring to.
In this case UserState is from
System.ComponentModel.AsyncCompletedEventArgs
public object UserState
{
get;
}
Thanks for your time .
|
|
|
|
|
|
Snap!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Snap as in crackle and pop,
|
|
|
|
|
Children's playing card game[^], used for teaching number recognition etc.. Both turn a card over at the same time and if both are the same e.g. a 9 then the first to call out 'Snap' wins all cards laid down so far. Winner is one who gets all cards or most in a given time.
So 'Snap' is used when two people do the same thing at the same time.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for clearing that up for me.
For me the association was more like when some fragile part in ones mind breaks and you "snap".
|
|
|
|
|
I am just looking for a simple answer to the question thats all
|
|
|
|
|
Please do NOT post the same question in more than one forum. Very rude.
Please delete this one.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
ok i deleted it from ask a question section. so does anyone know the answer?
|
|
|
|
|
Great! After I went through all the trouble editing your question you decide to delete it.
Isn't life a bummer!
|
|
|
|
|
so i guess no one knows the answer..oh well
|
|
|
|
|
SciGama wrote: var userCallback = e.UserState as Action<bool>
Your question is little bit confusing for me. whatever
If a class supports multiple asynchronous methods, or multiple invocations of a single method
then UserState property is used to determine which task raised the MethodNameCompleted event by checking the value of UserState property
|
|
|
|
|
Why can't I do the serialization successfully? I get an execption at the serialize line, yet I can do this using BinaryFormatter and SOAP Formatter. What am I missing?
public class person
{
public person() { ;}
public string firstname;
public string lastname;
public int Age;
}
public class persons
{
public persons() { }
public ArrayList personlist = new ArrayList();
}
<pre>[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
person p = new person();
p.firstname = "Tim";
p.lastname = "Duncan";
p.Age = 34;
persons ps = new persons();
ps.personlist.Add(p);
FileStream fs = File.Create("C:\\Temp\\test.xml");
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
xs.Serialize(fs,ps);
}
|
|
|
|
|
I think that
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
Should be
XmlSerializer xs = new XmlSerializer(typeof(persons));
and persons should have the Serializable attribute.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
your suggestion did not work. I still get an InvalidOperationexception at the serialize line! The exception says "unable to cast an object of type xmlSerialization.persons to type system.collections.Arraylist".
modified on Tuesday, December 14, 2010 8:24 PM
|
|
|
|
|
Software2007 wrote: unable to cast an object of type xmlSerialization.persons to type system.collections.Arraylist
Just use List<Person> for the collection of person in place of ArrayList .I think that will work.
|
|
|
|
|
your suggestion worked. The 2 samples below worked. Could you tell me why I can't use ArrayList though? Is there anything else I need to do to get Arraylist to work, or does it just not work?
Thanks
public List<person> personlist = new List<person>();
...
...
XmlSerializer xs = new XmlSerializer(typeof(persons));
xs.Serialize(fs,ps);
OR
public List<person> personlist = new List<person>();
.....
.....
XmlSerializer xs = new XmlSerializer(typeof(List<person>));
xs.Serialize(fs,ps.personlist);
|
|
|
|
|
Software2007 wrote: Could you tell me why I can't use ArrayList though?
You could use it, But I just was giving you a alternate way of accomplishing task.
See THIS[^], You might get idea on how to use ArrayList Serialization.
And for the serialization I think second one is appropriate.
|
|
|
|
|
When you get exceptions of a 'general' type like InvalidOperationException it is important to investigate the Inner Exception to determine the exact cause.
Just in case you do not know how to do this. When the Exception dialog pops up look below and to the left of the main 'Troubleshooting Tips' box and you will see a 'View Detail' link under 'Actions'. Click it. Expand the 'Inner Exception' node and you will see lots of useful stuff.
The important one in this case is the Message, which before making the changes I suggested said that "it was unable to convert persons to an ArrayList " and after making the changes said "person was unexpected and that use of XmlInclude attribute was recommended".
Following this up led me to Troubleshooting Common Problems....[^] on MSDN.
Have a read and see if it helps you to resolve your problem. If not, I have the solution so post a message and I'll explain it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Ok,got it. Basically I needed the syntax like the following. I need to do some more reading I guess.
Type[] extraTypes = new Type[1];
extraTypes[0] = typeof(person);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList), extraTypes);
Thanks
modified on Wednesday, December 15, 2010 9:34 AM
|
|
|
|
|
|
public class Program
{
[Serializable]
public class person
{
public person()
{
;
}
public string firstname;
public string lastname;
public int Age;
}
[
XmlInclude(typeof(person))
]
public class persons
{
public persons()
{
}
public ArrayList personlist = new ArrayList();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
person p = new person();
p.firstname = "Tim";
p.lastname = "Duncan";
p.Age = 34;
persons ps = new persons();
ps.personlist.Add(p);
FileStream fs = File.Create("C:\\Temp\\test.xml");
XmlSerializer xs = new XmlSerializer(typeof(persons));
xs.Serialize(fs, ps);
}
}
The List<whatever> solution works because a generic List is strongly typed. It returns an instance of a 'whatever' when you index into it. ArrayList however, returns an instance of Object and the serialization code cannot, for whatever reason, resolve the object into a person.
Using XmlInclude , very rough potted explanation here , says "Hey I'm using instances of person in here somewhere, so if you find something you can't resolve, try person before bombing out."
Hope this helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|