Click here to Skip to main content
15,889,403 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to Make my Automatic Login works with this site ??? Pin
Manfred Rudolf Bihy20-Nov-13 6:26
professionalManfred Rudolf Bihy20-Nov-13 6:26 
GeneralRe: How to Make my Automatic Login works with this site ??? Pin
KishanAhir20-Nov-13 7:45
KishanAhir20-Nov-13 7:45 
Questioni am binding counrty dropdownlist from database data in that i want to display india first is it possible with use of sql query Pin
Member 957694920-Nov-13 0:52
Member 957694920-Nov-13 0:52 
QuestionRe: i am binding counrty dropdownlist from database data in that i want to display india first is it possible with use of sql query Pin
thatraja20-Nov-13 1:35
professionalthatraja20-Nov-13 1:35 
AnswerRe: i am binding counrty dropdownlist from database data in that i want to display india first is it possible with use of sql query Pin
thatraja20-Nov-13 1:51
professionalthatraja20-Nov-13 1:51 
Question[Solved] SqlCeException (0x80004005) Pin
emma.sun.sts19-Nov-13 23:33
emma.sun.sts19-Nov-13 23:33 
AnswerRe: SqlCeException (0x80004005) PinPopular
OriginalGriff20-Nov-13 5:34
mveOriginalGriff20-Nov-13 5:34 
GeneralRe: SqlCeException (0x80004005) Pin
emma.sun.sts20-Nov-13 9:36
emma.sun.sts20-Nov-13 9:36 
oh yes. I was silly. Smile | :) 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); //get date from date time picker
     cmd.Parameters.AddWithValue("@p_EndDate", dtpEND.Value);
     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());
 }//------------------------------------------------------------------------------------

private void updateDS()
{
    DataRow dRow = ds1.Tables["upnp_daily"].NewRow(); //Step 1: create new row in Dataset

    dRow[1] = dateTimeStmp; //Step 2: Assign value to columns
    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); //Step 3: Add the row

    UpdateDB();

    MaxRows++; //Step 4: increment row no
    inc = MaxRows - 1; //Step 5: set inc to max row no
    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"]);// use DataAdapter of cb
}//----------------------------------------------------------------------

private void closeSQLserver()
{
    con.Close();//. close connection
}

GeneralRe: SqlCeException (0x80004005) Pin
Pete O'Hanlon20-Nov-13 9:48
mvePete O'Hanlon20-Nov-13 9:48 
GeneralRe: SqlCeException (0x80004005) Pin
emma.sun.sts20-Nov-13 10:01
emma.sun.sts20-Nov-13 10:01 
QuestionSQL database compatibility issue and database data reset Pin
emma.sun.sts19-Nov-13 20:34
emma.sun.sts19-Nov-13 20:34 
QuestionSkydrive File Upload Pin
mdsajidfaizan19-Nov-13 20:08
professionalmdsajidfaizan19-Nov-13 20:08 
AnswerRe: Skydrive File Upload Pin
Abhinav S19-Nov-13 21:26
Abhinav S19-Nov-13 21:26 
QuestionRead email attachments using C# Pin
surenred19-Nov-13 18:15
surenred19-Nov-13 18:15 
AnswerRe: Read email attachments using C# Pin
Richard MacCutchan19-Nov-13 21:51
mveRichard MacCutchan19-Nov-13 21:51 
AnswerRe: Read email attachments using C# Pin
BillWoodruff20-Nov-13 6:58
professionalBillWoodruff20-Nov-13 6:58 
QuestionUnable to write frame to the video writer Pin
mharicz19-Nov-13 17:41
mharicz19-Nov-13 17:41 
AnswerRe: Unable to write frame to the video writer Pin
Richard Andrew x6419-Nov-13 17:45
professionalRichard Andrew x6419-Nov-13 17:45 
QuestionHow to create Sublime Text like Command Palette in DotNet C# Desktop Application Pin
Sanket S Sonavane19-Nov-13 14:45
Sanket S Sonavane19-Nov-13 14:45 
AnswerRe: Create Sublime Text like Command Palette in DotNet C# Desktop Application Pin
Mycroft Holmes19-Nov-13 15:25
professionalMycroft Holmes19-Nov-13 15:25 
GeneralRe: Create Sublime Text like Command Palette in DotNet C# Desktop Application Pin
Sanket S Sonavane19-Nov-13 16:00
Sanket S Sonavane19-Nov-13 16:00 
AnswerRe: How to create Sublime Text like Command Palette in DotNet C# Desktop Application Pin
BillWoodruff19-Nov-13 19:01
professionalBillWoodruff19-Nov-13 19:01 
GeneralRe: How to create Sublime Text like Command Palette in DotNet C# Desktop Application Pin
Sanket S Sonavane19-Nov-13 20:36
Sanket S Sonavane19-Nov-13 20:36 
QuestionData is not stored to data source path mentioned in solution explorer Pin
emma.sun.sts19-Nov-13 14:24
emma.sun.sts19-Nov-13 14:24 
AnswerRe: Data is not stored to data source path mentioned in solution explorer Pin
Richard Andrew x6419-Nov-13 17:54
professionalRichard Andrew x6419-Nov-13 17:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.