Click here to Skip to main content
15,915,019 members
Home / Discussions / C#
   

C#

 
QuestionRegular Expression Control Pin
NaNg1524127-May-06 4:56
NaNg1524127-May-06 4:56 
AnswerRe: Regular Expression Control Pin
Guffa27-May-06 5:14
Guffa27-May-06 5:14 
QuestionRe: Regular Expression Control Pin
NaNg1524127-May-06 5:35
NaNg1524127-May-06 5:35 
GeneralRe: Regular Expression Control Pin
Guffa27-May-06 7:16
Guffa27-May-06 7:16 
GeneralRe: Regular Expression Control Pin
NaNg1524127-May-06 7:28
NaNg1524127-May-06 7:28 
AnswerRe: Regular Expression Control Pin
Guffa27-May-06 8:35
Guffa27-May-06 8:35 
AnswerRe: Regular Expression Control Pin
Al Ortega27-May-06 6:12
Al Ortega27-May-06 6:12 
QuestionSql +Arraylist + Datagridview Pin
JelleM27-May-06 4:09
JelleM27-May-06 4:09 
Hello,

I've got a table orders with 3 fields:
- date
- productid
- amount
productid & amount are values seperated by commas, f.e.: productid = 1,2 amount = 3,4 (which means there are 3 products "1" and 4 products "2").
Now, I want to select a field by date and get the value of productid & amount and put them in an array (or arraylist?).
Than, I want to fill a datagridview with again 2 colums (amount & productid) with that data.
So for the example the datagridview should look like:
3 1
4 2

This is what I wrote:

<br />
bill.Rows.Clear();<br />
SqlCommand myCommand = new SqlCommand("SELECT * FROM orders WHERE date = @date", connect);<br />
myCommand.Parameters.AddWithValue("@date", DateTime.Parse(listOrders.Text.ToString().Substring(0, 19)));<br />
SqlDataReader myReader = myCommand.ExecuteReader();<br />
while (myReader.Read())<br />
{<br />
amounts = myReader["amount"].ToString();<br />
products = myReader["productid"].ToString();<br />
}<br />
myReader.Close();<br />
<br />
string[] product = new string[products.Split(' ').Length];<br />
string[] amount = new string[amounts.Split(' ').Length];<br />
<br />
product = products.Split(' ');<br />
amount = amounts.Split(' ');<br />
<br />
for (int i = 0; i <= product.Length; i++)<br />
{<br />
bill.Rows.Add(amount[i], product[i], 1, 2);<br />
}<br />


But I always get an error near the product = products.Split ..
System.NullReferenceException was unhandled<br />
Message="Object reference not set to an instance of an object."

I don't really think the code is 100% ok, but can somebody help?
Thanks!
AnswerRe: Sql +Arraylist + Datagridview Pin
Colin Angus Mackay27-May-06 6:09
Colin Angus Mackay27-May-06 6:09 
GeneralRe: Sql +Arraylist + Datagridview Pin
JelleM27-May-06 10:45
JelleM27-May-06 10:45 
QuestionAnother problem with two forms [modified] Pin
mariuszfryta27-May-06 3:54
mariuszfryta27-May-06 3:54 
AnswerRe: Another problem with two forms [modified] Pin
Sean8927-May-06 4:35
Sean8927-May-06 4:35 
GeneralRe: Another problem with two forms [modified] Pin
mariuszfryta27-May-06 4:52
mariuszfryta27-May-06 4:52 
GeneralRe: Another problem with two forms [modified] Pin
Sean8927-May-06 6:33
Sean8927-May-06 6:33 
GeneralRe: Another problem with two forms [modified] Pin
mariuszfryta27-May-06 7:08
mariuszfryta27-May-06 7:08 
QuestionHow can I close one form Pin
mariuszfryta27-May-06 3:41
mariuszfryta27-May-06 3:41 
AnswerRe: How can I close one form Pin
Sean8927-May-06 3:48
Sean8927-May-06 3:48 
GeneralRe: How can I close one form Pin
mariuszfryta27-May-06 3:49
mariuszfryta27-May-06 3:49 
AnswerRe: How can I close one form Pin
Stefan Troschuetz27-May-06 3:48
Stefan Troschuetz27-May-06 3:48 
QuestionHow do I use line endings in a class? Pin
WCup27-May-06 3:23
WCup27-May-06 3:23 
GeneralRe: How do I use line endings in a class? Pin
Guffa27-May-06 3:57
Guffa27-May-06 3:57 
GeneralRe: How do I use line endings in a class? Pin
WCup27-May-06 4:20
WCup27-May-06 4:20 
AnswerRe: How do I use line endings in a class? Pin
Guffa27-May-06 5:17
Guffa27-May-06 5:17 
QuestionComboBox in C# Pin
AbdulRahmanOfpk27-May-06 3:00
AbdulRahmanOfpk27-May-06 3:00 
AnswerRe: ComboBox in C# Pin
MoustafaS27-May-06 3:29
MoustafaS27-May-06 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.