Please help on this problem, Pretty Please

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When I use a stored procedure to insert data into a table and when the
Datagrid refreshes two new columns are added. The dataSet is set up with one
table with NO columns defined. Please help me on this. I have screen shots of
the before and after.

Here is the code:

sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLInsertSP;
sqlCommand.Parameters.Add("@aid",SqlDbType.Int,4);
sqlCommand.Parameters.Add("@type",SqlDbType.VarChar,50);
sqlCommand.Parameters["@aid"].Value = tAID;
sqlCommand.Parameters["@type"].Value = tValue;
sqlADBAdapt.InsertCommand = sqlCommand;

//This is the point where the Insert Statement is working but its adding two
new columns

sqlADBAdapt.Update(dataSet1);
sqlCommand.Parameters.Clear();
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLSelectSP;
try{
sqlADBAdapt.SelectCommand = sqlCommand;
sqlADBAdapt.Fill(dataSet1.Tables[0]);
}
catch(SqlException ae){
MessageBox.Show(ae.Message.ToString());
}
dataGrid1.DataSource = dataTable1;
dataGrid1.ReadOnly=true;
 
all your logic, and all your bugs, are in the SQL statements. You didn't
include the stored procs in your post, so there's not much I can do to help.

not sure what you mean "adding two new columns"... the datagrid will simply
reflect the columns that come back in your select stmt... has nothing to do
with the insert stmt.

--- Nick
 
Nick,

The last stored procedure wasn't complete here is the complete stored proc:

ALTER PROCEDURE dbo.assetInsert
(
@aid int,
@type char(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO asset_types(aid, type) VALUES (@aid, @type);
SELECT aid, type FROM asset_types WHERE (aid = @aid)



Nick Malik said:
all your logic, and all your bugs, are in the SQL statements. You didn't
include the stored procs in your post, so there's not much I can do to help.

not sure what you mean "adding two new columns"... the datagrid will simply
reflect the columns that come back in your select stmt... has nothing to do
with the insert stmt.

--- Nick

mattgcon said:
When I use a stored procedure to insert data into a table and when the
Datagrid refreshes two new columns are added. The dataSet is set up with one
table with NO columns defined. Please help me on this. I have screen shots of
the before and after.

Here is the code:

sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLInsertSP;
sqlCommand.Parameters.Add("@aid",SqlDbType.Int,4);
sqlCommand.Parameters.Add("@type",SqlDbType.VarChar,50);
sqlCommand.Parameters["@aid"].Value = tAID;
sqlCommand.Parameters["@type"].Value = tValue;
sqlADBAdapt.InsertCommand = sqlCommand;

//This is the point where the Insert Statement is working but its adding two
new columns

sqlADBAdapt.Update(dataSet1);
sqlCommand.Parameters.Clear();
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLSelectSP;
try{
sqlADBAdapt.SelectCommand = sqlCommand;
sqlADBAdapt.Fill(dataSet1.Tables[0]);
}
catch(SqlException ae){
MessageBox.Show(ae.Message.ToString());
}
dataGrid1.DataSource = dataTable1;
dataGrid1.ReadOnly=true;
 
Nick,

I have some screen shots of the "new columns" if you would like me to send
them to you.
Here is the stored procedure:

ALTER PROCEDURE dbo.assetInsert
(
@aid int,
@type char(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO asset_types(aid, type) VALUES (@aid, @type);
SELECT

Nick Malik said:
all your logic, and all your bugs, are in the SQL statements. You didn't
include the stored procs in your post, so there's not much I can do to help.

not sure what you mean "adding two new columns"... the datagrid will simply
reflect the columns that come back in your select stmt... has nothing to do
with the insert stmt.

--- Nick

mattgcon said:
When I use a stored procedure to insert data into a table and when the
Datagrid refreshes two new columns are added. The dataSet is set up with one
table with NO columns defined. Please help me on this. I have screen shots of
the before and after.

Here is the code:

sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLInsertSP;
sqlCommand.Parameters.Add("@aid",SqlDbType.Int,4);
sqlCommand.Parameters.Add("@type",SqlDbType.VarChar,50);
sqlCommand.Parameters["@aid"].Value = tAID;
sqlCommand.Parameters["@type"].Value = tValue;
sqlADBAdapt.InsertCommand = sqlCommand;

//This is the point where the Insert Statement is working but its adding two
new columns

sqlADBAdapt.Update(dataSet1);
sqlCommand.Parameters.Clear();
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLSelectSP;
try{
sqlADBAdapt.SelectCommand = sqlCommand;
sqlADBAdapt.Fill(dataSet1.Tables[0]);
}
catch(SqlException ae){
MessageBox.Show(ae.Message.ToString());
}
dataGrid1.DataSource = dataTable1;
dataGrid1.ReadOnly=true;
 
Your original post does not show a couple of things:
1. Where dataTable1 is getting populated
2. Assuming that you omitted the code that sets dataTable1=
dataSet1.Tables[0], then you need to show us the stored procedure used to
populate it (the name of which would be stored in SQLSelectSP). This is most
likely where your problem is.

As the other responder said, this likely has nothing to do with your insert
statement - so don't know why you posted it... much less why you didn't post
the procedure that populates dataSet1.Tables[0].

Your grid is being bound to dataTable1 - so if dataTable1 is not pointing to
dataSet1.Tables[0] then you have to find out what is populating it.

GH


mattgcon said:
Nick,

I have some screen shots of the "new columns" if you would like me to send
them to you.
Here is the stored procedure:

ALTER PROCEDURE dbo.assetInsert
(
@aid int,
@type char(50)
)
AS
SET NOCOUNT OFF;
INSERT INTO asset_types(aid, type) VALUES (@aid, @type);
SELECT

Nick Malik said:
all your logic, and all your bugs, are in the SQL statements. You didn't
include the stored procs in your post, so there's not much I can do to help.

not sure what you mean "adding two new columns"... the datagrid will simply
reflect the columns that come back in your select stmt... has nothing to do
with the insert stmt.

--- Nick

mattgcon said:
When I use a stored procedure to insert data into a table and when the
Datagrid refreshes two new columns are added. The dataSet is set up
with
one
table with NO columns defined. Please help me on this. I have screen
shots
of
the before and after.

Here is the code:

sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLInsertSP;
sqlCommand.Parameters.Add("@aid",SqlDbType.Int,4);
sqlCommand.Parameters.Add("@type",SqlDbType.VarChar,50);
sqlCommand.Parameters["@aid"].Value = tAID;
sqlCommand.Parameters["@type"].Value = tValue;
sqlADBAdapt.InsertCommand = sqlCommand;

//This is the point where the Insert Statement is working but its
adding
two
new columns

sqlADBAdapt.Update(dataSet1);
sqlCommand.Parameters.Clear();
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = SQLSelectSP;
try{
sqlADBAdapt.SelectCommand = sqlCommand;
sqlADBAdapt.Fill(dataSet1.Tables[0]);
}
catch(SqlException ae){
MessageBox.Show(ae.Message.ToString());
}
dataGrid1.DataSource = dataTable1;
dataGrid1.ReadOnly=true;
 
Back
Top