|
Try something like this:
try
{
//insert your code here
}
catch(OleDbException ex)
{
Console.WriteLine("Message: " + ex.Message + "\n");
if(ex.InnerException != null)
Console.WriteLine("Message: " + ex.InnerException.Message + "\n");
foreach(OleDbError e in ex.Errors)
Console.WriteLine(e.Message + "\n");
}
|
|
|
|
|
OK, I got that coded in, but it doesn't seem to be actually catching the error. It's highlighting the lind of code inside the try, but it's still saying it's an "unhandled exception" and I'm not getting any console output.
What gives now?
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|
|
Possibly a typo in your post, but...
you select a field named [ClientName] (no space)
then try to get the field value from [Client Name] (space btwn Client & Name)
no such field exists in the readr, so an exception is thrown.
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|
|
Thanks for spotting that. It was actually an error in the code (I'd renamed the field and forgotten to update all references to it), but it's not causing the error. The code doesn't even get that far.
The ends can never justify the means. It is the means that determine the ends.
|
|
|
|
|
I took your code and for the most part is worked ok. I filled in some of the blanks and got this code to complie and run:
OleDbConnection cn = new OleDbConnection("User ID=xxx;Password=xxx;Initial Catalog=Northwind;Data Source=192.168.0.1;Provider=SQLOLEDB");
cn.Open();
System.Data.OleDb.OleDbCommand cmdGetNewClients = new System.Data.OleDb.OleDbCommand();
cmdGetNewClients.CommandText = @"SELECT LastName FROM Employees";
cmdGetNewClients.Connection = cn;
OleDbDataReader rdr = cmdGetNewClients.ExecuteReader();
ArrayList newClients = new ArrayList();
while(rdr.Read())
newClients.Add(rdr["LastName"]); <-- change made here
rdr.Close();
cn.Close();
Good luck.
|
|
|
|
|
Maybe you are forgetting to set the connection string in the OleDbConnection object.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello All,
I Lunch a form from another form how can i refresh the Firest form after I click button on the second form.
Regards
Hay
|
|
|
|
|
if you launch the second form from the first one you can add the first form in de constructor of the second. Something like
private Form m_form1<br />
<br />
public Form2(Form form1)<br />
{<br />
m_form1 = form1<br />
}<br />
<br />
your button click would be someting like:<br />
<br />
<code>private void HandleClick()<br />
{<br />
m_form1.Refresh();<br />
}<br />
<br />
basically you can call any public method in form1.<br />
<br />
Other more advanced option is to use the observer pattern. You can google for observer and c# to get more info on that subject.<br />
<br />
<br />
|
|
|
|
|
Hello,
I have a datagrid:
this.dataGridRevenues.DataMember = "LotYields";
this.dataGridRevenues.DataSource = this.dataset;
is there a way to display only certain rows in the grid, when loading the
dataset?
Thank you.
|
|
|
|
|
Try this
this.dataset.Tables("Products").Columns("Name").ColumnMapping = MappingType.Hidden
Alomgir Miah
Live Life King Size
|
|
|
|
|
Hello,
If you want to display specific rows based on the values they contain, you can create a DataView, and set the RowFilter property. Then bind the Datagrid to the DataView.
|
|
|
|
|
you can also create your select statement to only return the rows you want. Which to me would seem to be the easiest.
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Hello,
I'm writing a little class that hooks up a list view to display the selection count in the status bar. It's working great except that I found one little problem: in one of my forms, I have a tree control on the left, and a list view on the right. If I select another item in the tree, the list view is cleared and filled again with some other items (unselected, of course), but I never get the SelectedIndexChanged event.
Is there anyway I could detect when a new item is added and just update the count display? The only restriction is that I can't modify existing code.
Any ideas?
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hello,
I am trying to add a combobox to the datagrid, but I get an error
stating:
The type or namespace name 'DataGridComboBoxColumn' could not be found (are you missing a using directive or an assembly reference?)
I think I have all the directives, but maybe I am missing something?
|
|
|
|
|
I you are using .NET 1.x, then no, it doesn't exist. There are, however, several good articles explaining how to implement one here in CodeProject. Just search.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I can't find an article that would concentrate on .NET 1.x, all of them
assume that you use higher version.
|
|
|
|
|
|
Hi, somebody knows where can i find a Probability /statistical library (probability distributions) with source code?
I have search and no find anything free with sources.
Than you!
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
|
yeep
La realidad no es más que impulsos eléctricos del cerebro - Morpheus
|
|
|
|
|
Hi
I am using Microsoft.office.core (11.0) com library. I have added new button to the outlook toolbar. If i click on that it should get the currently focused email detals(like if i click on Reply,Forward etc...). I am able to get the entire folder emails detail but not exactly the selected email.
Thanks,
Inba S.
|
|
|
|
|
I have remote ftp server(with ip, user, pwd).
I want to make virtual ftp folder using shell extension which directs me to ftp server after asking about the user, pwd.
I have found some articles in c++ but I need c# code. Do I have to learn all the basics of shell extensions or is there any builtin tool that could do just that for me.
Can anyone tell me about the detailed descriptive article or any useful info on this issue .
|
|
|
|
|
What I want to do is choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table in the northwind database. I am not sure what to do, I think that the problem is in my SQL statement.
What I want to do is pick a bitmap and save it to a mdb database. I am using the northwind database.
Here is my code. I have been reading on this and have been able to copy a bitmap from the "Photo" field in the "Employees" table in the northwind database, to a field in the same table that I made named Photo2.
<br />
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
this.oleDbDataAdapter1.Fill(ds1, "Employees");<br />
IDTxtBx.DataBindings.Add("Text", ds1, "Employees.EmployeeID");<br />
firstNameTxtBx.DataBindings.Add("Text", ds1, "Employees.FirstName");<br />
<br />
bm = BindingContext[ds1, "Employees"];<br />
bm.PositionChanged += new EventHandler(bm_PositionChanged);<br />
bm_PositionChanged(null, null);<br />
}<br />
<br />
private void bm_PositionChanged(Object sender, EventArgs e)<br />
{<br />
image = null;<br />
this.pictureBox1.Image = null;<br />
<br />
string sqlText = "SELECT Photo FROM Employees WHERE EmployeeID=" +<br />
IDTxtBx.Text;<br />
<br />
OleDbCommand cmd = new OleDbCommand(sqlText, oleDbConnection1);<br />
<br />
this.oleDbConnection1.Open();<br />
try<br />
{<br />
int bufferSize = 100;<br />
byte[] outbyte = new byte[bufferSize];<br />
long retVal = 0;<br />
long startIndex = 0;<br />
<br />
OleDbDataReader dr = cmd.ExecuteReader (CommandBehavior.SequentialAccess);<br />
dr.Read();<br />
<br />
if(!dr.IsDBNull(0))<br />
{<br />
MemoryStream ms = new MemoryStream();<br />
<br />
retVal = dr.GetBytes(0, startIndex, outbyte, 0, <br />
bufferSize);<br />
<br />
while(retVal == bufferSize)<br />
{<br />
ms.Write(outbyte, 0, outbyte.Length);<br />
<br />
startIndex += bufferSize;<br />
<br />
retVal = dr.GetBytes(0, startIndex, outbyte, 0, <br />
bufferSize);<br />
}<br />
<br />
ms.Write(outbyte, 0, (int)retVal - 1);<br />
<br />
image = ms.ToArray();<br />
}<br />
}<br />
<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.ToString());<br />
}<br />
<br />
finally<br />
{<br />
this.oleDbConnection1.Close();<br />
}<br />
<br />
if(image != null)<br />
{<br />
MemoryStream ms = new MemoryStream(image);<br />
try<br />
{<br />
<br />
}<br />
<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.ToString());<br />
}<br />
ms.Close();<br />
}<br />
} <br />
<br />
string sqlWrite = "UPDATE " + "Employees" + " SET Photo2 = Photo WHERE EmployeeID = " + IDTxtBx.Text;<br />
<br />
OleDbCommand cmdWrite = new OleDbCommand(sqlWrite, this.oleDbConnection1);<br />
<br />
OleDbParameter prm;<br />
if(image != null)<br />
{<br />
prm = new OleDbParameter("Photo2", OleDbType.VarBinary, <br />
image.Length, ParameterDirection.Input, false,<br />
0, 0, null, DataRowVersion.Current, image);<br />
}<br />
<br />
else<br />
{<br />
prm = new OleDbParameter("Photo2", OleDbType.VarBinary, 0,<br />
ParameterDirection.Input, false,<br />
0, 0, null, DataRowVersion.Current,<br />
System.DBNull.Value);<br />
}<br />
<br />
cmdWrite.Parameters.Add(prm);<br />
this.oleDbConnection1.Open();<br />
<br />
cmdWrite.ExecuteNonQuery();<br />
this.oleDbConnection1.Close();<br />
bm.EndCurrentEdit();<br />
this.oleDbDataAdapter1.Update(ds1.Tables["Employees"]);<br />
Instead of copying field "Photo" to "Photo2" how can I choose a bitmap file, with a opendialogbox and save the bitmap to a field named "Photo" in the "Employees" table.
|
|
|
|
|
You're gonna need lots of COM interop for this. You'll need to setup a virtual drive that maps to Employees table, and integrate that drive into the shell. I'd look into the "C# does shell" set of articles on this site.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
I'm not entirely clear on what you are trying to do here. If all you are trying to do is copy the content of an existing field [photo] to another field [photo2] in the same tabel, then your update statement has no need for the parameter you are adding (and is probably confulsed by it). You don't need to read the data to copy it, it suffices to just set the value of one field to another in the update statement. If you want to write the content of the memory stream, then change the sql to
"UPDATE Employees SET Photo2 = ? WHERE EmployeeID = " + IDTxtBx.Text;
then the parameter you added will substitute for the ? placeholder and should work just fine
It is generally not a good idea to name parameters the same as fields in the table you are addressing, aside from the confusion it causes in the code, it may also cause errors...
Oledb doesn't understand named parameters like SQL server does, it expects placeholders, then matches them up by the order the paramters are added to the collection...
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
The opposite of the religious fanatic is not the fanatical atheist but the gentle cynic who cares not whether there is a god or not.
Eric Hoffer
|
|
|
|