Click here to Skip to main content
15,881,173 members
Home / Discussions / C#
   

C#

 
QuestionGenereate XML file from sql in C# Pin
Md. Rayhan Kabir8-Oct-12 18:17
Md. Rayhan Kabir8-Oct-12 18:17 
AnswerRe: Genereate XML file from sql in C# Pin
Sarath C8-Oct-12 22:42
Sarath C8-Oct-12 22:42 
Questionhelp in solving a problem Pin
michae1108-Oct-12 6:24
michae1108-Oct-12 6:24 
AnswerRe: help in solving a problem Pin
Richard MacCutchan8-Oct-12 6:57
mveRichard MacCutchan8-Oct-12 6:57 
AnswerRe: help in solving a problem Pin
Dave Kreskowiak8-Oct-12 11:00
mveDave Kreskowiak8-Oct-12 11:00 
AnswerRe: help in solving a problem Pin
Abhinav S8-Oct-12 17:37
Abhinav S8-Oct-12 17:37 
AnswerRe: help in solving a problem Pin
Paul Conrad10-Oct-12 7:46
professionalPaul Conrad10-Oct-12 7:46 
QuestionUsing a datagridview to maintain SQL server database table Pin
Member 80860588-Oct-12 1:35
Member 80860588-Oct-12 1:35 
First off, let me apologise if this seems a really basic question, but I've been searching for some answers/guidance for weeks.
I have a windows form with a Datagridview (DGV) bound via a bindingsource to a data table which is filled from a simple "Select * from table".
I also have an "Update" button.
I want the user to make changes to existing data in the grid and potentially add a new row using the blank row at the end of the DGV. When the user clicks the "Update" button I want to loop through the rows in the DGV(or underlying whatever) and, if a row has been changed or added, I want to call a stored procedure with column data parameters and an "action" parameter ("I" for insert, "U" for update, etc.)
On the "update" click, I have the code behind shown below.
However, when I click on the Update" button I get a runtime error indicating that "DataRow row in (dgvDocumentName.DataSource as DataTable" is null. I'm guessing that this is the wrong casting. If so, what should be the casting to allow me to iterate over the rows. If not, then what else am I doing wrong? Any help please would be fantastic. Thanks, James
C#
private void btnUpdate_Click(object sender, EventArgs e)
{
  dgvDocumentName.EndEdit();
  foreach (DataRow row in (dgvDocumentName.DataSource as DataTable).Rows)
  {
    if (row.RowState != DataRowState.Unchanged)
    {
      String sAction;

      switch (row.RowState)
      {
        case DataRowState.Added:
          sAction = "I";
          break;
        case DataRowState.Deleted:
          sAction = "D";
          break;
        case DataRowState.Modified:
          sAction = "U";
          break;
        default:
          sAction = "U";
          break;
      }
      documentsTableAdapter.procActionDocuments(Convert.ToInt32(row["colDocumentID"]),
                                                row["colDocumentName"].ToString(),
                                                Convert.ToInt32(row["colDocumentType"]),
                                                row["colDocumentText"].ToString(),
                                                sAction);
    }
  }
}

QuestionC# select part of file name Pin
classy_dog7-Oct-12 16:00
classy_dog7-Oct-12 16:00 
AnswerRe: C# select part of file name Pin
Abhinav S7-Oct-12 17:47
Abhinav S7-Oct-12 17:47 
AnswerRe: C# select part of file name Pin
Pete O'Hanlon7-Oct-12 20:17
mvePete O'Hanlon7-Oct-12 20:17 
QuestionC# search for specific folder in directory Pin
classy_dog7-Oct-12 10:19
classy_dog7-Oct-12 10:19 
AnswerRe: C# search for specific folder in directory Pin
Ravi Bhavnani7-Oct-12 15:36
professionalRavi Bhavnani7-Oct-12 15:36 
Questioninvoke DoubleClick event Pin
Jassim Rahma7-Oct-12 9:03
Jassim Rahma7-Oct-12 9:03 
AnswerRe: invoke DoubleClick event Pin
JF20157-Oct-12 9:12
JF20157-Oct-12 9:12 
GeneralRe: invoke DoubleClick event Pin
BobJanova9-Oct-12 0:07
BobJanova9-Oct-12 0:07 
QuestionC# linq with 3 tables Pin
sc steinhayse7-Oct-12 7:56
sc steinhayse7-Oct-12 7:56 
AnswerRe: C# linq with 3 tables Pin
Aasif Chanandin8-Oct-12 5:11
Aasif Chanandin8-Oct-12 5:11 
AnswerRe: C# linq with 3 tables Pin
gazmendmehmeti8-Oct-12 21:52
gazmendmehmeti8-Oct-12 21:52 
QuestionWhy is my control added three times? Pin
GrooverFromHolland7-Oct-12 7:01
GrooverFromHolland7-Oct-12 7:01 
AnswerRe: Why is my control added three times? Pin
DaveyM697-Oct-12 8:09
professionalDaveyM697-Oct-12 8:09 
GeneralRe: Why is my control added three times? Pin
GrooverFromHolland7-Oct-12 8:42
GrooverFromHolland7-Oct-12 8:42 
GeneralRe: Why is my control added three times? Pin
DaveyM697-Oct-12 9:01
professionalDaveyM697-Oct-12 9:01 
AnswerRe: Why is my control added three times? Pin
Alan N7-Oct-12 8:34
Alan N7-Oct-12 8:34 
GeneralRe: Why is my control added three times? Pin
DaveyM697-Oct-12 9:02
professionalDaveyM697-Oct-12 9:02 

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.