|
Excuse me,my English is poor.
When I used Webbrowser to browse some page.
Sometimes it would pop up MessageBox which I need to click the OK.
How to automatically detect the appearence of MessageBox and let it disapper.
or is there have any other way?
thaks
|
|
|
|
|
i want to insert unicode character(arabic) from c# to sql server 2005. but sql server is not supporting the unicode .
sadia
|
|
|
|
|
Just a helpful hint.
Delete the post below and next time you can just
modify your post to fix the 'subject'.
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
i want to insert unicode character(arabic) from c# to sql server 2005. but sql server is not supporting the unicode .
sadia
|
|
|
|
|
rehab1 wrote: but sql server is not supporting the unicode
I used to store Arabic data in SQL server for years.
do you use nvarchar and ntext fields? or varchar and text?
|
|
|
|
|
hi,
what would be the probable cause why i received this kind of error message...
this is my code:
try
{
foreach(DataGridViewRow row in dataGridView4.Rows)
{
long itemcode = 0;
string description = "";
int quantity = 0;
string unit = "";
itemcode = Convert.ToInt64(row.Cells[0].Value);
description = row.Cells[1].Value.ToString();
quantity = Convert.ToInt32(row.Cells[2].Value);
unit = row.Cells[3].Value.ToString();
String query = "INSERT INTO test(itemcode,description,quantity,unit) VALUES (itemcode,description,quantity,unit)";
MySqlCommand command = new MySqlCommand(query, connection);
command.ExecuteNonQuery();
}
}
catch (MySqlException mse)
{
MessageBox.Show(mse.Message);
}
}
jing
|
|
|
|
|
Where is the debugger popping the error out.
What line?
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
hi,
thanks for the reply...
the following lines:
description = row.Cells[1].Value.ToString();
unit = row.Cells[3].Value.ToString();
these two lines of code are string, i wonder why it has an error.
pls. help
thanks,
jing
|
|
|
|
|
Like PIEBALDconsult said below,
You need to use the debugger to find out what line.
God Bless,
Jason
DavidCrow wrote: It would not affect me or my family one iota. My wife and I are in charge of when the tv is on, and what it displays.
I do not need any external input for that.
|
|
|
|
|
hi,
ok thanks a lot...
God Bless
jing
|
|
|
|
|
Some value is null. Try debugging to see what line throws the exception. If you still can't figure it out, then post more information.
|
|
|
|
|
hi,
thanks for the reply..
the following 2 lines received the error message..
description = row.Cells[1].Value.ToString();
unit = row.Cells[3].Value.ToString();
regard
jing
|
|
|
|
|
Then either row, row.Cells, row.Cells[1], or row.Cells[1].Value is null. The debugger will show the value of each of them so it should be easy to find.
|
|
|
|
|
hi,
thanks..
yap,through the debugger,i've found out that row.Cell[1].Value is null.i'm trying to fix it right now...
jing
|
|
|
|
|
hi,
by the way will you please help me on how to insert values from the datagridview to the database table?
waiting for your reply
jing
|
|
|
|
|
In your
String query = "INSERT INTO test(itemcode,description,quantity,unit) VALUES (itemcode,description,quantity,unit)";
You'll want to use parameters for itemcode,description,quantity,unit
I'm not as familiar with MySql, but in Sql Server I'd prefix each with an @
@itemcode,@description,@quantity,@unit
Then instantiate a MySqlParameter for each and add them to the command's parameter collection.
Roughly: command.Parameters.Add ( new MySqlParameter ( "@itemcode" , itemcode ) ;
But if you're going to be inserting a bunch of data in a loop, you'll want something like: command.Parameters.Add ( new MySqlParameter ( "@itemcode" , typeof(itemcode) ) ;
then in the loop: command.Parameters [ "@itemcode" ].Value = itemcode ; (will that work?)
|
|
|
|
|
This is untested, and I don't usually use DataGridViews or MySql:
try
{
connection.Open() ;
MySqlCommand command = new MySqlCommand
(
"INSERT INTO test(itemcode,description,quantity,unit) VALUES (@itemcode,@description,@quantity,@unit)"
,
connection
) ;
foreach ( DataGridViewColumn col in dataGridView4.Columns )
{
command.Parameters.Add ( new MySqlParameter ( "@" + col.DataPropertyName , col.ValueType ) ;
}
command.Transaction = connection.BeginTransaction() ;
foreach(DataGridViewRow row in dataGridView4.Rows)
{
foreach ( DataGridViewCell cel in row.Cells )
{
command.Parameters [ "@" + cel.DataPropertyName ].Value = cel.Value ;
}
command.ExecuteNonQuery() ;
}
command.Transaction.Commit ;
}
catch ( MySqlException mse )
{
command.Transaction.Rollback ;
MessageBox.Show ( mse.Message ) ;
}
finally
{
connection.Close() ;
}
|
|
|
|
|
P.S. Using the technique above you can write a library routine that will even create the SQL statement, and you could simply pass it a reference to any DataGridView and the name of the table into which to sert the data, and never (hardly ever) write an INSERT statement again:
InsertData ( "test" , dataGridView4 ) ;
|
|
|
|
|
hi,
ok, it try to get the logic of your program so I could migrate it to MySql...
regards
jing
|
|
|
|
|
balanjingot wrote: String query = "INSERT INTO test(itemcode,description,quantity,unit) VALUES (itemcode,description,quantity,unit)";
Won't work. C# isn't going to magically convert the variable names in th VALUES clause to the appropriate things.
Best approach would be to make the list in the VALUES clause use parameters.
"INSERT INTO test(itemcode,description,quantity,unit) VALUES ( @itemcode,@description,@quantity,@unit)"
//What is a MySqlCommand? System.Data.SqlCommand is a sealed class, so you can't derive from it...
MySqlCommand command = new MySqlCommand(query, connection);
command.Parameters.Add( new SqlParameter("@itemcode",itemcode);
... the rest, in order...
command.ExecuteNonQuery();
I would suppose that one other likely cause is that your MySqlCommand Class is flawed, and the constructor
silently fails...
|
|
|
|
|
hi everybody,
thanks for your reply and suggestions, finally i got the solution to my problem...
my revised code:
private void button13_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < dataGridView4.Rows.Count -1; i++)
{
DataGridViewRow row = dataGridView4.Rows[i];
long itemcode = 0;
string description = "";
int quantity = 0;
string unit = "";
itemcode = Convert.ToInt64(row.Cells[0].Value);
if (description != null)
{
description = row.Cells[1].Value.ToString() + "";
}
quantity = Convert.ToInt32(row.Cells[2].Value);
unit = row.Cells[3].Value.ToString();
String query = "INSERT INTO test(itemcode,description,quantity,unit) VALUES ("
+ " " + itemcode
+ " ,'" + description + "'"
+ " , " + quantity
+ " ,'" + unit + "'"
+ " )";
MySqlCommand command = new MySqlCommand(query, connection);
MessageBox.Show(command.ExecuteNonQuery().ToString());
}
}
thanks guys
regards
jing
|
|
|
|
|
1) Check if row.Cells[X].Value is null or DBnull before converting or ToString()ing them
2) Catch also (Exception ex) and System.Diagnostics.Debug.WriteLine("Error! Source: ", ex.Source + ", Message: " + ex.Message); to see what happened. You can also do this:
if(ex.InnerException != null)
System.Diagnostics.Debug.WriteLine(ex.InnerException.Source + ", " + ex.innerException.Message);
Hope this helps...
|
|
|
|
|
hi,
thanks, my program already worked out!!
regards
jing
|
|
|
|
|
Having searched through tons of Google results, I found no single code/library about how to extract RAR [^] archives inside .NET.
Anyone can give me some links?
Thanks
Uwe
|
|
|
|
|
Have you had a look at this link on rarlab.com/[^]
The unrar.dll is what your looking for.
|
|
|
|
|