|
Sorry I am back so soon. For some reason when I save my database it tries to convert the Home Phone, Cell Phone, and Fax into System.Int32. I have them set on System.String.
" Failed to convert parameter value from String to a Int32. "
I have no code in there tring to convert it. Like I said in the database the textbox is set to System.String.
When I enter like: 123455 it works
When I enter like: 123-4567 it doesn't because of the dash.
|
|
|
|
|
Your post contains some confusing terminology so I am not sure what you mean by certain things.
Jacob Dixon wrote: For some reason when I save my database it tries to convert the Home Phone, Cell Phone, and Fax into System.Int32. I have them set on System.String.
By "save" did you mean "INSERT" or "UPDATE"?
Jacob Dixon wrote: Like I said in the database the textbox is set to System.String
The database knows nothing about textboxes. Nor does it use System.String. It uses char, varchar, nchar and nvarchar.
Could you post the relevant code? Both C# and SQL.
|
|
|
|
|
Sorry...
Under Data Sources I have a file called AddressesDataSet.Xsd, I right click it and go to Edit Dataset with Designer, which then shows a table of all my columns in the Addresses.mdf file (the database). Whhen I click a column in the table like HomePhone, CellPhone, or Fax, under the properties window it shows: Data Type: System.String. Here are all my "columns":
ID - primary key
FirstName
LastName
Address
City
State
Zip
Email
Picture
Notes
HomePhone
CellPhone
Fax
FirstName through State under the properties are set the Data Type to: System.String (which work and do not have any problems with)
Zip is set to System.Int32
Picture is set to System.Byte[]
The rest are System.String.
All of this I believe was automatically generated when I put the database in the project.
When I have a form open and I Drag and Drop the database to the form. I can choose to have all the columns displayed in DataGridView or all of the columns displayed on the form in TextBoxes, PictureBox, ComboBox, DateTimePicker, and more..
**wait**
I think I figured it out, I shouldn't be editing this in the DataSet. I should be doing this in the Addresses.mdf! Now I see where it is getting the INT and not varchar!
Ok now I feel stupid.. Thanks for the help though
|
|
|
|
|
I have one more question now that I got that fixed... in a foreach statement... I have a few If and else statements.. if you use return; that will exit the foreach loop won't it? For example:
if (DBNull.Value == r.Cells[7].Value) ; //if I use return; it will exit the foreachloop
else richTextBox1.Text += string.Format("Home Phone: {0}\n", r.Cells[7].Value.ToString());
Where the return; would be then it would go down here to the next If statement.
|
|
|
|
|
Jacob Dixon wrote: if you use return; that will exit the foreach loop won't it?
return exits the method. If you are in a foreach loop (or any type of loop) then that will, becuase it is inside the method, also end.
Jacob Dixon wrote: Where the return; would be then it would go down here to the next If statement
I don't understand what you mean by that. return exits the method. It won't progess to any more statements, including if statements, in the method.
|
|
|
|
|
Sorry... here I will paste the entire coding.. what I ended up doing was just leaving it blank and it seems to work....
foreach (DataGridViewRow r in theTableDataGridView.Rows)
{
richTextBox1.Text += string.Format("{0} {1}\n", r.Cells[1].Value.ToString(), r.Cells[2].Value.ToString());
if (DBNull.Value == r.Cells[3].Value);
else richTextBox1.Text += string.Format("{0}\n", r.Cells[3].Value.ToString());
if (DBNull.Value == r.Cells[4].Value && DBNull.Value == r.Cells[5].Value && DBNull.Value == r.Cells[6].Value);
else if (DBNull.Value == r.Cells[4].Value && DBNull.Value != r.Cells[5].Value && DBNull.Value != r.Cells[6].Value) richTextBox1.Text += string.Format("{0}, {1}\n", r.Cells[5].Value.ToString(), r.Cells[6].Value.ToString());
else if (DBNull.Value != r.Cells[4].Value && DBNull.Value == r.Cells[5].Value && DBNull.Value != r.Cells[6].Value) richTextBox1.Text += string.Format("{0}, {1}\n", r.Cells[4].Value.ToString(), r.Cells[6].Value.ToString());
else if (DBNull.Value != r.Cells[4].Value && DBNull.Value == r.Cells[5].Value && DBNull.Value == r.Cells[6].Value) richTextBox1.Text += string.Format("{0}\n", r.Cells[4].Value.ToString());
else if (DBNull.Value == r.Cells[4].Value && DBNull.Value != r.Cells[5].Value && DBNull.Value == r.Cells[6].Value) richTextBox1.Text += string.Format("{0}\n", r.Cells[5].Value.ToString());
else if (DBNull.Value == r.Cells[4].Value && DBNull.Value == r.Cells[5].Value && DBNull.Value != r.Cells[6].Value) richTextBox1.Text += string.Format("{0}\n", r.Cells[6].Value.ToString());
else richTextBox1.Text += string.Format("{0}, {1} {2}\n", r.Cells[4].Value.ToString(), r.Cells[5].Value.ToString(), r.Cells[6].Value.ToString());
if (DBNull.Value == r.Cells[7].Value);
else richTextBox1.Text += string.Format("Home Phone: {0}\n", r.Cells[7].Value.ToString());
if (DBNull.Value == r.Cells[8].Value);
else richTextBox1.Text += string.Format("Cell Phone: {0}\n", r.Cells[8].Value.ToString());
if (DBNull.Value == r.Cells[9].Value);
else richTextBox1.Text += string.Format("Fax Number: {0}\n", r.Cells[9].Value.ToString());
if (DBNull.Value == r.Cells[10].Value);
else richTextBox1.Text += string.Format("Email Address: {0}\n", r.Cells[10].Value.ToString());
if (DBNull.Value == r.Cells[12].Value);
else richTextBox1.Text += string.Format("Notes: {0}\n", r.Cells[12].Value.ToString());
richTextBox1.Text += "\n\n";
}
It appears to be work.. See I just left the IF statements without the RETURN. It seems to be working, I haven't ran into any problems yet..
Basically I just wanted to have it take the VALUE from the CELLS in a datagridview and display them in a certain format in a RichTextBox. Now If the cells were NULL then I did not want it to do anything.
Sorry to be so confusing, I'm trying to explain what I am trying to do.. Like I said it appears to be working and I thank you for trying to help me out.
-- Jacob Dixon
|
|
|
|
|
|
Yes! Thanks! As long as it skips the Else statement that is right after the IF statement!
|
|
|
|
|
Jacob Dixon wrote: Yes! Thanks! As long as it skips the Else statement that is right after the IF statement!
Umm... You do know how if statements work. Don't you?
if (some expression is true)
{
}
else
{
}
So, if you landed in the first block in the if statement, the code in the second block (after the else ) will not run.
Remember that if you have multiple statements you must enclose them in the braces. You can get away without the braces if you only have one statement.
|
|
|
|
|
Jacob Dixon wrote: As long as it skips the Else statement that is right after the IF statement!
I just re-read that if statement and it looks confusing
if (DBNull.Value == r.Cells[3].Value);
else richTextBox1.Text += string.Format("{0}\n", r.Cells[3].Value.ToString());
The reason it is confusing is that you have a do nothing semi-colon after the if. This is not normal practice (and if you are doing that as a matter of course then I suggest you stop)
The normal practice would be to reverse the if statement. So that the if has a != (not equal) instead of an == (equals) operator.
i.e.
if (DBNull.Value != r.Cells[3].Value)
richTextBox1.Text += string.Format("{0}\n", r.Cells[3].Value.ToString());
You might also want to consider using a StringBuilder to build your string then finally assign it to the RichTextBox . It will be faster, especially for larger sets of data.
|
|
|
|
|
Yes I understand how the If statement works and I think you are correct about reversing them. I tried using the continue statement that someone mentioned before... like:
if (DBNull.Value == r.Cells[12].Value) continue;
else richTextBox1.Text += string.Format("Notes: {0}\n", r.Cells[12].Value.ToString());
richTextBox1.Text += "\n\n";
the problem with this is if Cells[12] was actually DBNull, then for some reason it would skip the richTextBox1.Text += "\n\n"; ... now when I left continue out, it would work correctly. The program actually works like I wanted it to. I do think that you are correct and there are better ways of doing what I wanted it to do (which I'm sure you know). I'm still learning how things work exactly, and still learning how to make them more code friendly. Thanks
|
|
|
|
|
Jacob Dixon wrote: the problem with this is if Cells[12] was actually DBNull, then for some reason it would skip the richTextBox1.Text += "\n\n";
That is because continue moves to the start of the next iteration skipping any remaining statements in the current iteration.
|
|
|
|
|
Jacob Dixon wrote: When I enter like: 123-4567 it doesn't because of the dash.
You need to loop through the string and when you encounter a numeric character, add it to a temporary string, and ignore the none numeric characters. When done with the loop, you should be able to convert the temporary string to int32 with no problem.
---modified
Int32 is not always going to work if you include area codes. You might want to consider Int64 if you have store the phone numbers as integers.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
hi all
i work with database and i connetion to it
when aplay to connet to it the application send to me this message
Error [IM002][Microsoft][ODBC Driver Manager] DataSource name not found and no default driver specifies
thanks for any body help me
Thaer
|
|
|
|
|
There's something wrong with your connection string.
You need to provide details of this if you want help.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Thaer Hamael wrote: DataSource name not found
Check to make sure that the data source you're connecting to has been setup properly. In WinXP go to [Start -> Settings -> Control Panel -> Administrative Tools -> Data Sources (ODBC)] to View/Modify your systems ODBC connections.
|
|
|
|
|
ODBC is soooo '80s... get with ADO.net, there's likely a provider for your database.
|
|
|
|
|
Hello All:
How can I add an icon for any element inside list view,
thanks
|
|
|
|
|
Step1 :
use one ImageList and load all required images !!!
Step 2:
Use ListViewItem Class object ListItemobj
Step3:
ListItemObj.ImageIndex= set image index from ImageList
Hope this will help you
|
|
|
|
|
i have created a report using crystal report and i want to open it in reportViwer in C# 2005 how can i do that ?
|
|
|
|
|
The ReportViewer is for SSRS reports, not Crystal Reports.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
so how can i display the crystal report
|
|
|
|
|
Did you try searching[^] for an answer to your question yourself?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
sure, so how to use reportviwer ?
|
|
|
|
|
shabonaa wrote: sure, so how to use reportviwer ?
I already told you, you can't use the Report Viewer control for Crystal Reports
The Report Viewer control is for displaying SSRS reports.
Which part of 'you can't use it' didn't you understand?
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|