|
0) No, it's not urgent for us.
1) You should have posted this question in ASP.NET forum[^]
2) What have you tried?
3) Did you search Google?
4) Here a simple idea for solution.
Consider you have a table like below, add another column DisplayOrder
----------------------------------
CountryID CountryName DisplayOrder
----------------------------------
1 US 3
2 UK 2
3 India 1
----------------------------------
Now, write a query with sorting order - DisplayOrder column
SELECT CountryID, CountryName, DisplayOrder FROM TblCountry ORDER BY DisplayOrder ASC;
Now bind the query to DropDownlist .
5) From next time, follow this[^]
|
|
|
|
|
Hi,
I've been trying to get data from sql database within selected dates defined by datetimepicker. I've followed all necessary connection setup and query but there is this error SqlCeException at da.Fill(ds1, "upnp_daily"). It says a parameter is missing. I have tried all means but I couldn't spot where exactly goes wrong.
The following is my code. I really do appreciate it if someone could help me. Thanks in advance!
//-----Code-----
System.Data.SqlServerCe.SqlCeConnection con;
System.Data.SqlServerCe.SqlCeDataAdapter da;
DataSet ds1;
private void connectSQLserver()
{
//Connecting to SQL Server Express Database
string strDataSource = @"Data Source=C:\Visual Studio 2010\Projects\UPNP_Form_F\UPNP_Form_F\bin\Debug\upnp_database.sdf";
con = new System.Data.SqlServerCe.SqlCeConnection();
con.ConnectionString = strDataSource;
con.Open();
ds1 = new DataSet();
SqlCeCommand cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM upnp_daily_energy WHERE Date >= @p_StartDate AND Date <= @p_EndDate";
cmd.Parameters.Add("@p_StartDate", SqlDbType.DateTime).Value = dtpSTART; //get date from date time picker
cmd.Parameters.Add("@p_EndDate", SqlDbType.DateTime).Value = dtpEND;
cmd.Connection = con;
da = new System.Data.SqlServerCe.SqlCeDataAdapter(cmd.CommandText, cmd.Connection);
try //run the query
{
da.Fill(ds1, "upnp_daily"); //run the query
}
catch (Exception e2)
{
MessageBox.Show("Error 7: " + e2.ToString()); //<<--- Error here!
}
MessageBox.Show("Connection Open"); //<<---DEBUG
MaxRows = ds1.Tables["upnp_daily"].Rows.Count; //get no of rows in DataSet
MessageBox.Show("No of rows in DataSet = " + MaxRows.ToString());
}//------------------------------------------------------------------------------------
modified 28-Nov-13 2:33am.
|
|
|
|
|
I'm not that surprised:
cmd.Parameters.Add("@p_StartDate", SqlDbType.DateTime).Value = dtpSTART; No, it doesn't.
It tries to pass a DateTimePicker control into the parameter as a DateTime value!
Try this:
cmd.Parameters.Add("@p_StartDate", SqlDbType.DateTime).Value = dtpSTART.Value;
cmd.Parameters.Add("@p_EndDate", SqlDbType.DateTime).Value = dtpEND.Value; Or better:
cmd.Parameters.AddWithValue("@p_StartDate", dtpSTART.Value);
cmd.Parameters.AddWithValue("@p_EndDate", dtpEND.Value);
|
|
|
|
|
oh yes. I was silly. I should be passing dtpSTART.Value.
But the same error still remains and all my database data is wiped out everytime I call this upon a button click. Here is what I have implement. Could you please kindly take a look? I'm really quite at a loss.
System.Data.SqlServerCe.SqlCeConnection con;
System.Data.SqlServerCe.SqlCeDataAdapter da;
DataSet ds1;
private void btnGetData_Click(object sender, EventArgs e)
{
connectSQLserver();
updateDS();
closeSQLserver();
}
private void connectSQLserver()
{
string strDataSource = @"Data Source=C:\Visual Studio 2010\Projects\UPNP_Form_F\UPNP_Form_F\bin\Debug\upnp_database.sdf";
con = new System.Data.SqlServerCe.SqlCeConnection();
con.ConnectionString = strDataSource;
con.Open();
ds1 = new DataSet();
SqlCeCommand cmd = new SqlCeCommand();
cmd.CommandText = "SELECT * FROM upnp_daily_energy WHERE Date >= @p_StartDate AND Date <= @p_EndDate";
cmd.Parameters.AddWithValue("@p_StartDate", dtpSTART.Value);
cmd.Parameters.AddWithValue("@p_EndDate", dtpEND.Value);
cmd.Connection = con;
da = new System.Data.SqlServerCe.SqlCeDataAdapter(cmd.CommandText, cmd.Connection);
try
{
da.Fill(ds1, "upnp_daily");
}
catch (Exception e2)
{
MessageBox.Show("Error 7: " + e2.ToString());
}
MessageBox.Show("Connection Open");
MaxRows = ds1.Tables["upnp_daily"].Rows.Count;
MessageBox.Show("No of rows in DataSet = " + MaxRows.ToString());
}
private void updateDS()
{
DataRow dRow = ds1.Tables["upnp_daily"].NewRow();
dRow[1] = dateTimeStmp;
dRow[2] = fIrrad;
dRow[3] = fDPM_A; dRow[4] = fPR_A;
dRow[5] = fDPM_B; dRow[6] = fPR_B;
dRow[7] = fDPM_C; dRow[8] = fPR_C;
dRow[9] = fDPM_D; dRow[10] = fPR_D;
dRow[11] = fTotal; dRow[12] = fPR;
ds1.Tables["upnp_daily"].Rows.Add(dRow);
UpdateDB();
MaxRows++;
inc = MaxRows - 1;
MessageBox.Show("Record is saved in Dataset.");
}
private void UpdateDB()
{
System.Data.SqlServerCe.SqlCeCommandBuilder cb;
cb = new System.Data.SqlServerCe.SqlCeCommandBuilder(da);
cb.DataAdapter.Update(ds1.Tables["upnp_daily"]);
}
private void closeSQLserver()
{
con.Close();
}
|
|
|
|
|
Change the Build property on your database so that it's set to Update if newer, rather than Update always.
|
|
|
|
|
So there is nothing wrong with my code above? The error is one parameter missing at da.Fill( ) and I couldn't spot where exactly go wrong
|
|
|
|
|
Hi,
Even when I create sql database with the latest version, there is still this compatibility error, and so I added UpgradeDatabasewithCaseSensitive() as mentioned in http://msdn.microsoft.com/en-us/library/bb896160(v=vs.100).aspx in my form.
After I debug and compile my program for the first time, the program runs fine subsequently without UpgradeDatabasewithCaseSensitive() anymore. But after some undefined time, when I debug and compile again, the compatibility error appears again and all the data I have saved so far in my database is all gone.
I decided to switch on and off visual studio window and run the program again. Sometimes, I can run the program without needing UpgradeDatabasewithCaseSensitive(). Sometimes, I need to include it. I decided to switch on and off my laptop and run the program again. The problem still remains. The program runs sometimes without needing to upgrade and sometimes needs to upgrade (then all the data is gone).
Why doesn't the data remain in database? Can someone help please? I'm still a novice with c#. Below is my code.
STS
//code
System.Data.SqlServerCe.SqlCeConnection con;
System.Data.SqlServerCe.SqlCeDataAdapter da;
DataSet ds1;
private void connectSQLserver()
{
//Connecting to SQL Server Express Database
con = new System.Data.SqlServerCe.SqlCeConnection();
con.ConnectionString = @"Data Source=C:\Visual Studio 2010\Projects\Form\Form\bin\Debug\database.sdf";
UpgradeDatabasewithCaseSensitive(); //update only once first time
try
{
con.Open();
}
catch (Exception e)
{
MessageBox.Show("Error : " + e.ToString());
}
ds1 = new DataSet();
string sql = "SELECT * From upnp_daily_energy";
da = new System.Data.SqlServerCe.SqlCeDataAdapter(sql, con);
try //run the query
{
da.Fill(ds1, "upnp_daily"); //run the query
}
catch (Exception e2)
{
MessageBox.Show("Error : " + e2.ToString());
}
MessageBox.Show("Connection Open"); //<<---DEBUG
}
public static void UpgradeDatabasewithCaseSensitive()
{
// Default case-insentive connection string.
// Note that .sdf is an old 3.1 version database.
string connStringCI = "Data Source= upnp_database.sdf; LCID= 1033";
// Set "Case Sensitive" to true to change the collation from CI to CS.
string connStringCS = "Data Source= upnp_database.sdf; LCID= 1033; Case Sensitive=true";
SqlCeEngine engine = new SqlCeEngine(connStringCI);
// The collation of the database will be case sensitive because of
// the new connection string used by the Upgrade method.
try
{
engine.Upgrade(connStringCS);
}
catch (Exception ex3)
{
MessageBox.Show("Error 2: " + ex3.ToString());
}
SqlCeConnection conn = null;
conn = new SqlCeConnection(connStringCI);
conn.Open();
//Retrieve the connection string information - notice the 'Case Sensitive' value.
List<keyvaluepair<string, string="">> dbinfo = conn.GetDatabaseInfo();
Console.WriteLine("\nGetDatabaseInfo() results:");
foreach (KeyValuePair<string, string=""> kvp in dbinfo)
{
Console.WriteLine(kvp);
}
}
modified 20-Nov-13 2:42am.
|
|
|
|
|
How to upload a file on pulic folder in SkyDrive using C# code. Please help me out.
please suggest through example.
Thank you.
|
|
|
|
|
|
How to Read E-Mail and the Attachments using C#.
the mail maybe gmail or yahoomail or hot mail or webmail
|
|
|
|
|
|
There are several articles here on CodeProject that demonstrate reading e-mail, with, or without, attachments. Just search.
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|
pls help me with this error
heres my code:
if (capture == null)
{
try
{
Image<Bgr, byte> capture1 = new Image<Bgr, byte>("1.GIF");
VideoWriter v = new VideoWriter("output.mp4",-1, 1, 1920, 1080, true);
v.WriteFrame(capture1);
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}
#endregion
if (capture != null)
{
if (captureInProgress)
{
button2.Text = "Start!";
Application.Idle -= ProcessFrame;
}
else
{
button2.Text = "Stop";
Application.Idle += ProcessFrame;
}
captureInProgress = !captureInProgress;
}
trim2010
|
|
|
|
|
Have a look at the Inner Exception to see if any more detail is provided.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Create Sublime Text like Command Palette in DotNet C# Desktop Application
How to create a C# Desktop app with a textbox control where menu entries can be autocompleted and triggered.
Just check screenshot three in http://www.sublimetext.com/
Command Palette is triggered by using the CTRL + SHIFT + P hotkey in Sublime Text .
Sublime Command Palette[^]
How i visualize the Design
Menu Control entries will be either fetched from Database / XML / JSON during application load, these same source will be fed as a source for the Autocomplete Textbox.
Exploring the Unexplored.
modified 19-Nov-13 22:03pm.
|
|
|
|
|
You have not asked a question, all you have done is stated what you want to do!
Start specifying/designing/building the app and when you run across a problem that you cannot find an answer using the search tools available (CP and Google) then ask here.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Will do that , Thanks
Exploring the Unexplored.
|
|
|
|
|
I don't use the Sublime text editor (I use UltraEdit when I'm not using Visual Studio), but I looked at Sublime's animated screen-shot demo, and the picture of the "Command Palette" window.
I don't see any technical barrier that would prevent you from creating a WinForm Application with this kind of user-interface. You could use one of the MS Controls that supports auto-complete, a ComboBox, or TextBox, as a basis for the pop-up window. I'd probably choose to make it a UserControl.
I suggest you explore the articles here on CodeProject on auto-complete for ideas, inspiration, and, possibly, useful code: [^].
"What Turing gave us for the first time (and without Turing you just couldn't do any of this) is he gave us a way of thinking about and taking seriously and thinking in a disciplined way about phenomena that have, as I like to say, trillions of moving parts.
Until the late 20th century, nobody knew how to take seriously a machine with a trillion moving parts. It's just mind-boggling." Daniel C. Dennett
|
|
|
|
|
Thanks for your inputs
Exploring the Unexplored.
|
|
|
|
|
Hi,
I'm still a novice and I've been working on this for days, hope someone can help.
I have my connection string defined in Form1.cs as below where data is to be stored in database.sdf.
con.ConnectionString = @"Data Source=C:\Visual Studio 2010\Projects\Form\Form\bin\Debug\database.sdf"
When I added data source using the wizard in SE, the path shown is "C:\Visual Studio 2010\Projects\Form\Form\database.sdf" and another database.sdf is physically created in that directory. But new data I entered is not saved there.
So, I change con.ConnectionString to @"Data Source=C:\Visual Studio 2010\Projects\Form\Form\database.sdf" and run the program. It keeps telling me the data file has been created by an earlier version and to upgrade using SqlCeEngine.Upgrade(). So I use UpgradeDatabasewithCaseSensitive() method as mentioned here but the problem still remains.
http://msdn.microsoft.com/en-us/library/bb896160(v=vs.100).aspx[^]
What is going on? How can sync the data source path mentioned in Form1.cs and what is shown in solution explorer?
STS
|
|
|
|
|
Check the Properties window for the database file itself. See if it is marked to copy to output directory after the build.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Yes, it is already marked as Copy if newer. The problem still remains.
Currently the data is stored in @"Data Source=C:\Visual Studio 2010\Projects\Form\Form\bin\Debug\database.sdf" and not in C:\Visual Studio 2010\Projects\Form\Form\database.sdf".
|
|
|
|
|
It seems you have two separate problems.
1. The version compatibility problem
2. The inability to know which copy of the database file your program is connecting to.
I might try renaming or removing one or the other copy of the file to find out definitively which copy is being connected to by your program.
Unfortunately I can't be of much help with the version compatibility issue. Good luck.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi!
Yes. Two problems. I will figure out regarding the compatibility problem. Regarding the second one, I know which database my program is connected to.
My program runs with or without being connected to the Data Source in Solution Explorer (C:\Visual Studio 2010\Projects\Form\Form\database.sdf). The database connected to is where I have defined in my Form1.cs (@"Data Source=C:\Visual Studio 2010\Projects\Form\Form\bin\Debug\database.sdf"). There I'm confused. Don't I need the database physically defined in Data Sources and connected to my program? If so, how do I make it so that wizard doesn't create the default path but point to the database of my choice?
And thanks for your help so far! It's been much help.
STS
|
|
|
|
|
I am really fed up with .NET and C# and really wish I stayed with Java or anything else that isn't so contrary and idiotic . I recently, had a problem with an online report written with Developer Express Reporting tools within a .NET/C# intranet web-site. The report being a summary of the entire application utilized sub-reports to sub-reports to sub-reports, when one of the bottom-level sub-reports failed to be populated when it was working fine and there were no updates to any of the associated code. I spent days trying to figure out why it stopped working and to find a fix. In the end a friend familiar with this type of problem had me rename the method that was no longer firing then create a new method with exact same signature as the original method that wasn't working. When tested, the new empty method would fire just fine where the old method had quit working no matter what was done with it. Next I merely copied the original code from the old method to the new one, ran it and the report was fixed . My next step before publishing was to delete the original method.
I'd complain to DevEx, but I am sure they will insist it is a Visual Studio (2012 Ultimate) problem and Microsoft will say it is a DevEx problem, so I am posting my complaint here. The only kind of explanation I have is VS sometimes has a problem with recognizing method signatures as being valid and therefore will not execute them???
The other problem I have with this is at one sub-report level the method signature created is different than at the lower level. In this case the method that would not run was called:
private void xrInvAllegations_BeforePrint(object sender, PrintEventArgs e)
{ . . .
However, the equivalent method signature at the higher (Investigations sub-report control's level uses the following:
private void xrSacwisInvestigations_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{ . . .
I do NOT understand why the same method call would use two different sets of parameter signatures, which overly confuses the issue, and why one would just decide, I am not going to work anymore until you copy me into a new block with the exaxt same method signature!
I can't begin to express how totally frustrating this is and I definately hate to publish a fix on such a flimsy excuse for what was wrong. Can anyone explain a better reason why rewriting the exact same code should be used as fix for method that stops firing? us
|
|
|
|