Click here to Skip to main content
15,886,049 members
Home / Discussions / C#
   

C#

 
Questiondatetime picker in datagridview c# 2008 Pin
abcurl29-Sep-09 18:04
abcurl29-Sep-09 18:04 
AnswerRe: datetime picker in datagridview c# 2008 Pin
Not Active29-Sep-09 18:27
mentorNot Active29-Sep-09 18:27 
GeneralRe: datetime picker in datagridview c# 2008 Pin
abcurl29-Sep-09 18:30
abcurl29-Sep-09 18:30 
GeneralRe: datetime picker in datagridview c# 2008 Pin
Not Active29-Sep-09 18:37
mentorNot Active29-Sep-09 18:37 
QuestionRe: datetime picker in datagridview c# 2008 Pin
abcurl29-Sep-09 18:40
abcurl29-Sep-09 18:40 
AnswerRe: datetime picker in datagridview c# 2008 Pin
Not Active29-Sep-09 18:46
mentorNot Active29-Sep-09 18:46 
QuestionWCF,3Tier Pin
Member 232129329-Sep-09 17:47
Member 232129329-Sep-09 17:47 
QuestionModify a Dataset then apply dataset to sql server... What am I doing wrong Please? Pin
JollyMansArt29-Sep-09 12:25
JollyMansArt29-Sep-09 12:25 
Can Someone please help me. I am trying to learn the use of datasets....
I can easily grab the data without a dataset from this table and apply the changes back to the sql server. But when I use the dataset I can only retrieve the data from sql server. Everytime I try doing the following C# Code to update the data in a sql server table stored in a dataset then apply the dataset back to sql server. The Environment comes back to me and complains.

Here Is the error I keep getting:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.







private void btnOptionSaveChanges_Click(object sender, EventArgs e)
        {
            //http://support.microsoft.com/kb/307587
            //http://bytes.com/topic/c-sharp/answers/251248-reading-dataset
            //http://support.microsoft.com/kb/307587
            SQLObjects MySQLObjects = new SQLObjects();

                if (StandardProcedures.SQL_TestConnection(WhatIsMyConnectionString) == false)
                {
                    MessageBox.Show("There is an issue with the application's connection string or ability to communicate with SQL Server! No Changes will be made.");
                    //Environment.Exit(-1);
                    return;
                }
                if (!StandardProcedures.SQL_CheckToSeeIfTheObjectAlreadyExistsInSQLServer(WhatIsMyConnectionString, MySQLObjects.Table, "tblSoftwareControls"))
                {
                    MessageBox.Show("tblSoftwareControls table does not exist in the Database. No Changes will be made");
                    //Environment.Exit(-1);
                    return;
                }
                //string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
                //string sql = @"select top 1 * from tblSoftwareControls";
                //string sql = @"SELECT CompanyName, CopyRight, ConnectionString, SplashScreenTimer, SplashScreenImage, VersionOverride FROM tblSoftwareControls";
                string sql = @"SELECT * FROM tblSoftwareControls";
                
                SqlConnection conn = new SqlConnection(WhatIsMyConnectionString);

                try
                {
                    conn.Open();
                    SqlDataAdapter da = new SqlDataAdapter(sql, conn);
                    DataSet ds = new DataSet();
                    da.FillSchema(ds, SchemaType.Source, "tblSoftwareControls");
                    da.Fill(ds, "tblSoftwareControls");
                    //**************************************

                    //Update the dataset
                    DataTable dt = ds.Tables["tblSoftwareControls"];
                    DataRow dr;
                    if (dt.Rows.Count > 0)
                    {
                        dr = dt.Rows[0];
                        dr.BeginEdit();
                        dr["ConnectionString"] = txtApplicationConnectionString.Text;
                        dr["SplashScreenTimer"] = txtSplashScreenTimer.Text;
                        dr["VersionOverride"] = ckbxOverrideVersionByPass.Checked;
                        dr.EndEdit();
                        StandardProcedures.DebugLogWriter("Updated the record in tblSoftwareControls!");
                    }
                    else
                    {
                        dr = dt.NewRow();
                        dr["ConnectionString"] = txtApplicationConnectionString.Text;
                        dr["SplashScreenTimer"] = txtSplashScreenTimer.Text;
                        dr["VersionOverride"] = ckbxOverrideVersionByPass.Checked;
                        
                        //Pass the new object into the add method of the datatable
                        dt.Rows.Add(dr);
                        StandardProcedures.DebugLogWriter("Wrote a new record to tblSoftwareControls!");
                    }
                    //**************************************

                    //Update the sql database by sending it the data in the dataset.
                    // BEGIN SEND CHANGES TO SQL SERVER 

                    SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(da);
                    da.Update(ds, "tblSoftwareControls");
                    StandardProcedures.DebugLogWriter("DataSet modifications or additions or deletions has the modifications applied to the SQL Server Table.");
                    // END SEND CHANGES TO SQL SERVER
                        



                        /*

                    foreach (DataRow dr in dt.Rows)
                    {
                        txtApplicationConnectionString.Text = dr["ConnectionString"].ToString();
                        txtSplashScreenTimer.Text = dr["SplashScreenTimer"].ToString();
                        ckbxOverrideVersionByPass.Checked = StandardProcedures.Convert_TrueFalse(dr["VersionOverride"].ToString());
                    }
                    DataTable dt = ds.Tables["tblSoftwareControls"];
                    txtApplicationConnectionString.Text = dt.Columns["ConnectionString"].;
                    txtSplashScreenTimer.Text = dt.Columns["SplashScreenTimer"].;
                    ckbxOverrideVersionByPass.Checked = StandardProcedures.Convert_TrueFalse(dt.Columns["VersionOverride"]);
                    */
                }
                catch (Exception ex)
                {
                    StandardProcedures.ErrorLogWriter("Trying to populate the Options Tab: " + ex.ToString());    
                }
                finally
                {
                    conn.Close();
                }
        }

AnswerRe: Modify a Dataset then apply dataset to sql server... What am I doing wrong Please? Pin
JollyMansArt29-Sep-09 12:35
JollyMansArt29-Sep-09 12:35 
QuestionHow to run a wcf service in System Context? Pin
AndyASPVB29-Sep-09 11:44
AndyASPVB29-Sep-09 11:44 
AnswerRe: How to run a wcf service in System Context? Pin
Calla29-Sep-09 19:35
Calla29-Sep-09 19:35 
GeneralRe: How to run a wcf service in System Context? Pin
AndyASPVB30-Sep-09 8:43
AndyASPVB30-Sep-09 8:43 
QuestionFind First Row using WildCard and nonPrimary Column Pin
KCI-VA29-Sep-09 10:36
KCI-VA29-Sep-09 10:36 
AnswerRe: Find First Row using WildCard and nonPrimary Column [modified] Pin
Eddy Vluggen29-Sep-09 10:53
professionalEddy Vluggen29-Sep-09 10:53 
AnswerRe: Find First Row using WildCard and nonPrimary Column Pin
Henry Minute29-Sep-09 11:06
Henry Minute29-Sep-09 11:06 
QuestionRe: Find First Row using WildCard and nonPrimary Column [modified] Pin
KCI-VA30-Sep-09 2:18
KCI-VA30-Sep-09 2:18 
QuestionInsert/Update into Table with many fields. Pin
castrand129-Sep-09 9:59
castrand129-Sep-09 9:59 
AnswerRe: Insert/Update into Table with many fields. Pin
Not Active29-Sep-09 10:21
mentorNot Active29-Sep-09 10:21 
AnswerRe: Insert/Update into Table with many fields. Pin
Christian Graus29-Sep-09 10:31
protectorChristian Graus29-Sep-09 10:31 
AnswerRe: Insert/Update into Table with many fields. Pin
Dave Kreskowiak29-Sep-09 10:49
mveDave Kreskowiak29-Sep-09 10:49 
GeneralRe: Insert/Update into Table with many fields. Pin
castrand130-Sep-09 8:32
castrand130-Sep-09 8:32 
GeneralRe: Insert/Update into Table with many fields. Pin
Dave Kreskowiak30-Sep-09 14:38
mveDave Kreskowiak30-Sep-09 14:38 
GeneralRe: Insert/Update into Table with many fields. Pin
castrand12-Oct-09 7:43
castrand12-Oct-09 7:43 
QuestionLinkbutton, Target="_blank" Pin
JohnQuar129-Sep-09 7:28
JohnQuar129-Sep-09 7:28 
AnswerRe: Linkbutton, Target="_blank" Pin
JohnQuar129-Sep-09 10:07
JohnQuar129-Sep-09 10:07 

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.