Problem in inserting from datagrid

K

Krishna

Hi, I have developed a for dataentry by using datagird in C# windows
application, I am using combocolumns, textbox columns for the same,
two readonly textboxcolumns for those readonly columns i will assign
the default value through nulltextproperty. I am getting all these fine
it is inserting,updating without any problem.

But while inserting new rows it is not inserting values related to that
readonly textboxes, can some one help me regarding this, i have struck
in this....


Regards
Ramakrishna
 
L

Loki117

Whats probably happening is you haven't setup the parameter values in
your sql commands to point to those columns on the grid or that you
haven't set the "value" property you have simply set the text property.
Your SQL command parameters should have a Source column property
makesure that has been set.
 
K

Krishna

Hi, Thanks for the replay.

I specified sourse column and value for the same column, I am using the
following code, please go through the code.

_DataAdapterTitles.InsertCommand = _Conn.CreateCommand();
_DataAdapterTitles.InsertCommand.CommandText =
"INSERT INTO transactions
(trans_id,ac_code,trans_type,payment_type,trans_description,dbamount,cramount,uid,trans_date)
" +
"VALUES(@i1, @i2, @i3, @i4, @i5, @i6, @i7,@i8,@i9)";

// Add the parameters for INSERT
SqlParameter i1 = new
SqlParameter("@i1",SqlDbType.Char,21,"trans_id");
i1.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i1);

SqlParameter i2 = new
SqlParameter("@i2",SqlDbType.Char,5,"ac_code");
i2.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i2);

SqlParameter i3 = new
SqlParameter("@i3",SqlDbType.Char,4,"trans_type");
i3.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i3);

SqlParameter i4 = new
SqlParameter("@i4",SqlDbType.Char,4,"payment_type");
i4.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i4);

SqlParameter i5 = new
SqlParameter("@i5",SqlDbType.Char,200,"trans_description");
i5.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i5);

SqlParameter i6 = new
SqlParameter("@i6",SqlDbType.Decimal,0,"dbamount");
i6.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i6);

SqlParameter i7 = new
SqlParameter("@i7",SqlDbType.Decimal,0,"cramount");
i7.SourceVersion = DataRowVersion.Current;
_DataAdapterTitles.InsertCommand.Parameters.Add(i7);

SqlParameter i8 = new SqlParameter("@i8",SqlDbType.Char,10,"uid");
i8.SourceVersion = DataRowVersion.Current;
i8.Value=clsGeneral.uid;
_DataAdapterTitles.InsertCommand.Parameters.Add(i8);

SqlParameter i9 = new
SqlParameter("@i9",SqlDbType.DateTime,8,"trans_date");
i9.SourceVersion = DataRowVersion.Current ;
i9.Value=DateTime.Now.ToString("MM/dd/yyyy");
_DataAdapterTitles.InsertCommand.Parameters.Add(i9);
 

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