|
Hello
I´m using an excellent tutorial:
http://www.codeproject.com/KB/grid/usingdatagrid.aspx
I'm not using MS Access, what is recommended in the tutorial, but MS SQL Comapact Edition as Data Provider. This shoult doesn't make a different.
But every time I try to execute the following code, an error message appear.
And the dataGrid is not displayed on the form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
namespace DataGridViewTest
{
public partial class Form1 : Form
{
private System.Windows.Forms.DataGrid dataGrid1;
public Form1()
{
InitializeComponent();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataGrid1.Location = new System.Drawing.Point(20, 20);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(200, 100);
}
private void fnDisplayDataInDataGrid()
{
string conStr = "Data Source=C:\\CSharp\\DataGridViewTest\\DB_Personen.sdf";
SqlCeConnection conn = new SqlCeConnection(conStr);
conn.Open();
SqlCeDataAdapter adapter = new SqlCeDataAdapter("SELECT * FROM Adressen", conn);
DataSet ds = new DataSet();
adapter.Fill(ds, "Adresse");
this.dataGrid1.DataSource = ds.DefaultViewManager;
}
private void Form1_Load(object sender, EventArgs e)
{
fnDisplayDataInDataGrid();
}
}
}
The error message predicate I need a DLL. But wich DLL and where can I get it ?
A first chance exception of type 'System.DllNotFoundException' occurred in System.Data.SqlServerCe.dll
Can someone help me, please ?
Sincere regards
Samuel
|
|
|
|
|
There are a few things. Please edit uand use <pre></pre> tags around your code. I usaly don't bother reading unformated code
Doltsche wrote: A first chance exception of type 'System.DllNotFoundException' occurred in System.Data.SqlServerCe.dll
Witch dll? if you tried running without debug, windows usaly shows witch dll are missing. This is not problem with a code, better reinstal your database.
Or it coud be that you are refencingn to incorect dll. Try remove from reference and add again
|
|
|
|
|
Hello
Thanks for the answer.
Sorry for my english, I can only a little bit.
I have the Code now written in VS 2010 and added the same Datasource.
However, the previous error message doesn't appear anymore but a other message appear:
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll
Although, the Application run. But the DataGrid is still not shown.
I haven't any idea how I can solve this problem. Please help me. Thanks
regards
Samuel
|
|
|
|
|
I do not know whay this problems occour.
Doltsche wrote: But the DataGrid is still not shown
You mean data in DataGrid is not shown or DataGrid itself doesn't show?
In your code you forgot to use DataMember beside DataSource. Here is mine example and it worked. I didn't use MS Sql as i do not have installed. I usaly use MySQL.
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.TableName = "Boo";
dt.Columns.Add("Test");
dt.Columns.Add("Failed");
dt.Rows.Add(new Object[]{"Wil it work?","Hahaha, I lost my Mind"});
ds.Tables.Add(dt);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "Boo";
Look at the last line. That line is missing from your code. Have you tried using another test project using designer and auto generated code? I do not know witch tutorial recomend MS accsess as database, but that is the last thing on the list that I would reccomend. MS accsess is great for a Local database as long there is only one connection to it.
|
|
|
|
|
Hi all,
Im trying to write some data to a excel file. the problem is that if the file is open, then im getting a exception.
How can i catch/fix this ?
Thanks
|
|
|
|
|
Close it?
Or use liquid nitrogen.
|
|
|
|
|
With your question and info you provided there is a slim chance to anybody know what your problem is.
Witch Exception is thrown?
Priya Prk wrote: the problem is that if the file is open, then im getting a exception.
Please elaborate. As long your app has open you should be able to write. The impression I get from this part is: How do I open a Excel file while it was Exclusive opened by another application. (Exclusive opened means that file opened by one app cannot be accsessed by another App)
|
|
|
|
|
If the file is already opened (by Excel or any other app), then you have no choice but to wait until whichever process has the file open gets around to closing it. Then you can open the file in your app.
|
|
|
|
|
what's connection string for sdf file ?
|
|
|
|
|
|
I used this connectionString
"Data Source=|DataDirectory|TMCDataBase.sdf;Persist Security Info=False"
Error : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
|
|
|
|
|
How did you initialize the connection?
I think you have used this:
conn = new SqlConnection("Data Source=|DataDirectory|TMCDataBase.sd;Persist Security Info=False");
But the correct way is:
conn = new SqlCeConnection("Data Source=|DataDirectory|TMCDataBase.sd;Persist Security Info=False");
In order to use SqlCeConnection class, you should reference System.Data.SqlCe.dll.
|
|
|
|
|
I am looking for a way to subscribe to system events so when a new system event is added to the system event log, I can be notified and grab information about the event. So far I have found a way to grab system events, however I do not know how to use this to be notified when a new event has been logged. I also found a way to listen for system events, but this
way is limited to certain events and does not provide the information on the event that I need. Any suggestions on either a new way to get what I need or how to use what I already found? Thanks.
|
|
|
|
|
Solved, used EntryWrittenEventHandler in System.Diagnostics.EventLog
|
|
|
|
|
I need datagridview component that I can show picture and
Information of peopel in it (Like XamDataGrid)
please help me
|
|
|
|
|
How about DataGridViewImageColumn? Are you looking for something more than that?
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
datagrid like XamDataGrid but XamDataGrid is wpf I need component for win application
|
|
|
|
|
I don't know what WPF grid looks like so can't help.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
I have a very simple DataGridView:
public Form1()
{
InitializeComponent();
DataGridView dataGridView1 = new DataGridView();
DataTable dataTable = new DataTable();
dataGridView1.DataSource = new BindingSource(dataTable, null);
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
Console.WriteLine("There are " + dataGridView1.Rows.Count + " rows in your table.");
this.Controls.Add(dataGridView1);
}
The table is displayed correctly with one row, but the print out says there are zero rows in the table. Why is that? And if I want to obtain other information about rows and cells (such as their locations), how do I do that? I would prefer to keep my DataGridView bound because I find the filter functionality to be very useful.
|
|
|
|
|
arnold_w wrote: but the print out says there are zero rows in the table. Why is that?
There has to be some problem with your printing code. Try debug that or post it here.
arnold_w wrote: I want to obtain other information about rows and cells (such as their locations), how do I do that?
Try using GetCellDisplayRectangle method.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
d@nish wrote: arnold_w wrote:
but the print out says there are zero rows in the table. Why is that?
There has to be some problem with your printing code. Try debug that or post it here.
The code is posted here and the printing code is the second row from the end.
d@nish wrote: arnold_w wrote:
I want to obtain other information about rows and cells (such as their locations), how do I do that?
Try using GetCellDisplayRectangle method.
If I add the following code at the very end:
try
{
Rectangle cellRectangle = dataGridView1.GetCellDisplayRectangle(0, 0, true);
Console.WriteLine("The cell is located at " + cellRectangle.X + ", " + cellRectangle.Y + ".");
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("ArgumentOutOfRangeException. Additional info: " + e.Message);
}
I get an ArgumentOutOfRangeException saying the parameter is outside the valid range. What I missing here?
|
|
|
|
|
arnold_w wrote: The code is posted here and the printing code is the second row from the end
Sorry. I thought you are speaking of printing (hard copy) datagridview. I took a look at your code. Here are some comments:
1. Get rid of binding source and use this:
DataGridView dataGridView2 = new DataGridView();
DataTable dataTable = new DataTable();
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
dataGridView2.DataSource = dataTable;
2. What I found from debugging is that unless form is loaded, you don't get the row count. Not sure of reason* but you do get the count in load. So probably if you check for row count in the load event, you would get the correct result.
The second exception is also for the same reason. Put that as well in the Load event and I guess it should work.
*I have posted a question regarding same. You can check that and get to know the reason.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Ok, so I should do something like this instead:
public Form1()
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, System.EventArgs e)
{
DataGridView dataGridView1 = new DataGridView();
DataTable dataTable = new DataTable();
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
dataGridView1.DataSource = dataTable;
this.Controls.Add(dataGridView1);
Console.WriteLine("There are " + dataGridView1.Rows.Count + " rows in your table.");
}
?
It does seem to work properly.
|
|
|
|
|
d@nish wrote: 1. Get rid of binding source and use this:
DataGridView dataGridView2 = new DataGridView();
DataTable dataTable = new DataTable();
dataTable.Columns.Add("My Column");
dataTable.Rows.Add("My Cell Value");
dataGridView2.DataSource = dataTable;
Ooops, I just discovered that if I don't use BindingSource, I can't use the BindingSource.Filter method. The reason I want a bound form is that I need filter-functionality. Is there a workaround for this?
|
|
|
|
|
There is a RowFilter property (don't remember if it is of datatable.defaultview or of the datagridview). You can use that.
For your other post, check first if the designer file has the code to attach the event handler (+= thing). It depends on the way you create the event.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|