System.Data.NoNullAllowedException

G

Guest

I am using sql server, Visual Studio .NET and C#. My application uses windows
forms. The form that I am having a problem with has some text boxes and a
data grid. There are two sql tables (i.e task and task-details) each table
has the same primary key (service-order-number). The problem is I get a sql
message "Column "service-order-number" does not allow nulls". To the bust of
my knowledge I have not tried to write to the database yet. I am new at this
and need some help please!!!!

PS: there is a demo in the ADO.NET Visual.NET C# Chapter13, WinApps (09 -
Chield Form) that does what I am trying to do. This might help. Thanks

***** The code that crashes is:

public void EditDetail(CurrencyManager cm)
{
drvDetail = (DataRowView) cm.Current;
vueDetail = drvDetail.DataView;

this.BindingContext[vueDetail].Position = cm.Position;

***** This code setup the datagrid:

private void FormatTaskGrid()
{
DataGridTableStyle tbl = new DataGridTableStyle();
tbl.MappingName = "task-details";
DataGridTextBoxColumn col;
col = new DataGridTextBoxColumn();
col.MappingName = "taskid";
col.HeaderText = "Task ID";
col.Alignment = HorizontalAlignment.Center;
col.Width = 60;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "task-desc";
col.HeaderText = "Service Description";
col.Alignment = HorizontalAlignment.Center;
col.Width = 70;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "complete-date";
col.HeaderText = "Completion Date";
col.Alignment = HorizontalAlignment.Center;
col.Width = 80;
tbl.GridColumnStyles.Add(col);
col = new DataGridTextBoxColumn();
col.MappingName = "task-cost";
col.HeaderText = "Service Cost";
col.Alignment = HorizontalAlignment.Right;
col.Width = 90;
tbl.GridColumnStyles.Add(col);
grdTasks.TableStyles.Add(tbl);
}

***** and this is the code that calls the program that crashes *****

cmDetails.AddNew();
TaskDetail TaskDetail = new TaskDetail(snum, tnum, asize);
TaskDetail.EditDetail(cmDetails);
TaskDetail.Dispose();
 
C

Cor Ligthert [MVP]

Norm,

Mostly is this error when you try to add a row to a datatable while the
primarykey is not yet filled while it should be.

I hope this helps,

Cor
 
G

Guest

Thanks for your responce to my question. If I insert a key value, what will
happen when when I add a row. Do you have a suggestion on how to do this.

Norm
 
C

Cor Ligthert [MVP]

Norm,

Be sure that you add the primary key value, how did you supose that I can
answer this question when you have not in your sample where you add the row
to the table.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top