473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView System.NullRefe renceException On Read Only Values

Hello Everyone,

I have been trying to figure this one out for two days now. I have
created a DataGridView which is populated by an ObjectDataSourc e. My
problem occurs when I attempt to use the Edit feature of the
DataGridView. I have set several of the BoundField elements of the
DataGridView to ReadOnly="True" . When I attempt to use the Edit
feature to UPDATE the rows in the DataGridView I get a
System.NullRefe renceException for each of the ReadOnly BoundField
elements. When the BoundField is set to ReadOnly="False " the error
does not occur. I am including the code I use to populate the
DataGridView as well as the UPDATE code and the DataGridView ASP.NET
code as well. Thank you for your help in advance.
<asp:GridView ID="gvApplicant sNotMatched" runat="server"
AutoGenerateEdi tButton="True"
BackColor="Whit e" BorderColor="#9 99999"
BorderStyle="No ne" BorderWidth="1p x"
CellPadding="3"
DataSourceID="O bjectDataSource 1" AutoGenerateCol umns="False"
DataKeyNames="U N,PW,DB" GridLines="Vert ical">
<Columns>
<asp:BoundFie ld DataField="ID_N um"
HeaderText="Id Number" NullDisplayText ="Please Enter an ID" />
<asp:BoundFie ld DataField="SSN"
HeaderText="SSN " ReadOnly="True" />
<asp:BoundFie ld DataField="Firs t_Name"
HeaderText="Fir st Name" ReadOnly="True" />
<asp:BoundFie ld DataField="Last _Name"
HeaderText="Las t Name" ReadOnly="True" />
<asp:BoundFie ld DataField="Birt h_Date"
HeaderText="Dat e of Birth" ReadOnly="True" />
<asp:BoundFie ld DataField="UN"
HeaderText="Use r Name" Visible="False" />
<asp:BoundFie ld DataField="PW"
HeaderText="Pas sword" Visible="False" />
<asp:BoundFie ld DataField="DB"
HeaderText="Dat abase" Visible="False" />
</Columns>
<FooterStyle BackColor="#CCC CCC"
ForeColor="Blac k" />
<RowStyle BackColor="#EEE EEE" ForeColor="Blac k"
/>
<SelectedRowSty le BackColor="#008 A8C"
Font-Bold="True" ForeColor="Whit e" />
<PagerStyle BackColor="#999 999"
ForeColor="Blac k" HorizontalAlign ="Center" />
<HeaderStyle BackColor="#000 084"
Font-Bold="True" ForeColor="Whit e" />
<AlternatingRow Style BackColor="Gain sboro" />
</asp:GridView>

<asp:ObjectData Source ID="ObjectDataS ource1"
runat="server" SelectMethod="F indUnmachedAppl icants"
TypeName="Admis sionsWebService "
UpdateMethod="U pdateApplicatio nInfo">

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

[WebMethod]
public DataSet FindUnmachedApp licants(UserIde ntifier currentUser)
{
ConstructConnec tionStringFromU serIdentifier(c urrentUser);

DataSet CommonAppDataSe t_Unmatched = new DataSet();
DataTable errorTable = new DataTable();

#region construct errorTable

errorTable.Tabl eName = "Error Table";
errorTable.Colu mns.Add("ErrorE xists",
System.Type.Get Type("System.St ring"));
errorTable.Colu mns.Add("messag e",
System.Type.Get Type("System.St ring"));

#endregion

string CommonAppUnmatc hedDataQuery = String.Format(@ "
select name_master.id_ num as wrong_id,
hdx_adm_CommonA pp_import_stagi ng.Id_Num,
hdx_adm_CommonA pp_import_stagi ng.SSN,
hdx_adm_CommonA pp_import_stagi ng.First_Name,
hdx_adm_CommonA pp_import_stagi ng.Last_Name,
hdx_adm_CommonA pp_import_stagi ng.Birth_Dte as Birth_Date,
UN = '" + currentUser.Use rName + @"', PW = '" +
currentUser.Pas sword + @"',
DB = '" + currentUser.Dat abase + @"'
from hdx_adm_CommonA pp_import_stagi ng left join name_master

on hdx_adm_CommonA pp_import_stagi ng.id_num =
name_master.id_ num
where name_master.id_ num is null");

try
{
Conn.Open();
SelectCmd = new SqlCommand(Comm onAppUnmatchedD ataQuery,
Conn);
Adapter.SelectC ommand = SelectCmd;

Adapter.Fill(Co mmonAppDataSet_ Unmatched);
Conn.Close();
}
catch (Exception ex)
{
err.Add("An error occurred in FindUnmatchedAp plicants().");
err.Add(ex.ToSt ring());
err.Add(CommonA ppUnmatchedData Query);
DataRow errorRow = errorTable.NewR ow();
errorRow["ErrorExist s"] = "Error";
errorRow["message"] = err.ToString();
errorTable.Rows .Add(errorRow);
CommonAppDataSe t_Unmatched.Tab les.Add(errorTa ble);
}
return CommonAppDataSe t_Unmatched;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

[WebMethod]
public void UpdateApplicati onInfo(int ID_Num, string SSN, string
First_Name,
string Last_Name, string Birth_Date, string UN, string PW,
string DB)
{
bool ConnIsOpen = false;
string CommonAppUpdate dDataQuery = string.Empty;

ConnIsOpen = ConstructConnec tionString(UN, PW, DB);

// try
// {
CommonAppUpdate dDataQuery = String.Format(@ "
update hdx_adm_CommonA pp_import_stagi ng
set id_num = " + ID_Num + @"
where first_name = '" + First_Name.Trim () + @"'
and last_name = '" + Last_Name.Trim( ) + @"' and birth_dte =
'" + Birth_Date.Trim () + @"'");

if (SSN.Length == 9)
CommonAppUpdate dDataQuery += @" and ssn = " + SSN;
// }
// catch (Exception e2)
// {
// err.Add(@"An error occurred in UpdateApplicati onInfo(int
ID_Num, string SSN, string First_Name,
// string Last_Name, string Birth_Date, string UN,
string PW, string DB).");
// err.Add(e2.ToSt ring());
// }
try
{
Conn.Open();
UpdateCmd = new SqlCommand(Comm onAppUpdatedDat aQuery,
Conn);
Adapter.UpdateC ommand = UpdateCmd;

Adapter.UpdateC ommand.ExecuteN onQuery();
Conn.Close();
}
catch (Exception ex)
{
err.Add(@"An error occurred in UpdateApplicati onInfo(int
ID_Num, string SSN, string First_Name,
string Last_Name, string Birth_Date, string UN, string
PW, string DB).");
err.Add(ex.ToSt ring());
}
}

Sep 28 '06 #1
0 2290

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6398
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I gave it a try using the example given in
0
6916
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { fDeleteRow = false; if (chx_DeleteFlag.Checked) {
1
1749
by: DBC User | last post by:
Hi All, I am using a database which doesn't suppport and since I am using ORM I can not use join query to create table object mapping. So my question is I have a master table which has bunch of columns I want to display. Of those 3 of them are integer columns, which needed to be translated into string by looking up on a reference table....
3
4629
by: Daniel Manes | last post by:
I need a strategy to debug this situation... I can't put all the code involved, but here are some of the critical lines with comments: ------------------------- Private _parentDataCell As DataGridViewCell 'declare private field _parentDataCell = _parentDataGrid.Rows(rowIndex).Cells(columnIndex) 'set to a specific cell...
1
3502
by: Martin | last post by:
Hi, I'm having a problem with a datagridview control when trying to read the value of an unbound checkbox cell. The code below works fine if I click on any text cell, bound or unbound, and also if I click on a data bound checkbox cell. But it fails with null reference exception if I try to read the value on an unbound cell.
2
2011
by: John Tressle | last post by:
I've just started learning vb.net and although it's awesome I've been tearing my hair out trying to find a solution to this specific problem. I have a form with 2 data grid views and I would like the 2nd datagrid view to automatically be populated with relevant data when the selected row is changed on the first datagridview. I have created...
7
15625
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns...
0
5245
by: hydro123 | last post by:
I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following: // initialize varaibles from dataGridView double C1; double INF1; double T1; //Read String values from each dataGridView Cell String^C1s = safe_cast<String^>(dataGridView1->Value);...
6
10576
by: Ciaran | last post by:
I'm having a really strange issue with the DataGridView control in a VS2008 / .NET 3.5 winforms project. I have a simple form with a grid. In the form constructor I call a function to bind the grind to a DataTable, and then loop through the rows setting the background colour of the last cell to LightGrey and the cell itself to read-only if the...
0
7526
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7483
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.