Home > Archive > ASP .NET > November 2004 > [BUG?] (2) Update database using stored procedure and OleDbDataAdapter.Update
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[BUG?] (2) Update database using stored procedure and OleDbDataAdapter.Update
|
|
|
| As suggested by Cor Ligthert, i've created a simpler sample, with the same
problem; this is the full source code,
so everyone can try itself:
Access database "dati.mdb":
Tables:
"myTable"
Fields:
fNumber Numeric
fString VarChar(50)
No primary keys defined.
Stored Procedures:
"qry_Ins":
PARAMETERS [@fNumber] Long, [@fString] Text ( 255 );
INSERT INTO myTable ( fNumber, fString )
VALUES ([@fNumber], [@fString]);
C# Project: Only 1 WebForm (WebForm1.aspx)
//////////////////////////////////////////
// Code Start
//////////////////////////////////////////
private void Page_Load(object sender, System.EventArgs e)
{
OleDbConnection conn = new
OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=" + Server.MapPath("dati.mdb") + ";");
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM myTable", conn);
DataSet ds = new DataSet();
// The table is initially empty so ds has no rows
da.Fill(ds, "myTable");
OleDbCommand upCmd = new OleDbCommand("qry_Ins", conn);
upCmd.CommandType = CommandType.StoredProcedure;
upCmd.Parameters.Add("@fNumber", OleDbType.Integer, 0, "fNumber");
upCmd.Parameters.Add("@fString", OleDbType.VarChar, 50, "fString");
da.InsertCommand = upCmd;
int i = 1;
while (i<=20)
{
ds.Tables["myTable"].Rows.Add(new object[] {i, "data_" + i});
i++;
}
da.Update(ds, "myTable");
conn.Close();
conn = null;
}
//////////////////////////////////////////
// Code End
//////////////////////////////////////////
This is the output in the database after 1 execution of the above code:
fNumber fString
1 data_1
1 data_2
1 data_3
1 data_4
1 data_5
1 data_6
1 data_7
1 data_8
1 data_9
1 data_1
1 data_1
1 data_1
1 data_1
1 data_1
1 data_1
1 data_1
1 data_1
1 data_1
1 data_1
1 data_2
As visible, fNumber is always 1, and fString is truncated to 6 chars.
So, how to fix? It's a BUG???
| |
| Jeff Dillon 2004-11-30, 4:03 pm |
| What do you mean "output of the database". How are you printing out the
values below? I'm assuming you've opened the database in Access, and
widened the display grid columns?
Jeff
"joun" <joun@nospam.com> wrote in message
news:Rf0rd.58489$Ni.2006399@twister1.libero.it...
> As suggested by Cor Ligthert, i've created a simpler sample, with the same
> problem; this is the full source code,
> so everyone can try itself:
>
> Access database "dati.mdb":
> Tables:
> "myTable"
> Fields:
> fNumber Numeric
> fString VarChar(50)
> No primary keys defined.
> Stored Procedures:
> "qry_Ins":
> PARAMETERS [@fNumber] Long, [@fString] Text ( 255 );
> INSERT INTO myTable ( fNumber, fString )
> VALUES ([@fNumber], [@fString]);
>
>
> C# Project: Only 1 WebForm (WebForm1.aspx)
> //////////////////////////////////////////
> // Code Start
> //////////////////////////////////////////
>
> private void Page_Load(object sender, System.EventArgs e)
> {
>
> OleDbConnection conn = new
> OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
> "Data Source=" + Server.MapPath("dati.mdb") + ";");
>
> conn.Open();
>
> OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM myTable",
conn);
> DataSet ds = new DataSet();
>
> // The table is initially empty so ds has no rows
> da.Fill(ds, "myTable");
>
>
> OleDbCommand upCmd = new OleDbCommand("qry_Ins", conn);
> upCmd.CommandType = CommandType.StoredProcedure;
>
> upCmd.Parameters.Add("@fNumber", OleDbType.Integer, 0, "fNumber");
> upCmd.Parameters.Add("@fString", OleDbType.VarChar, 50, "fString");
>
>
> da.InsertCommand = upCmd;
>
> int i = 1;
> while (i<=20)
> {
> ds.Tables["myTable"].Rows.Add(new object[] {i, "data_" + i});
> i++;
> }
>
> da.Update(ds, "myTable");
>
> conn.Close();
> conn = null;
>
> }
> //////////////////////////////////////////
> // Code End
> //////////////////////////////////////////
>
> This is the output in the database after 1 execution of the above code:
>
> fNumber fString
> 1 data_1
> 1 data_2
> 1 data_3
> 1 data_4
> 1 data_5
> 1 data_6
> 1 data_7
> 1 data_8
> 1 data_9
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_2
>
> As visible, fNumber is always 1, and fString is truncated to 6 chars.
> So, how to fix? It's a BUG???
>
>
>
>
| |
| Jeff Dillon 2004-11-30, 4:03 pm |
| And "varchar" in an Access database? You meant Text, correct?
Jeff
"joun" <joun@nospam.com> wrote in message
news:Rf0rd.58489$Ni.2006399@twister1.libero.it...
> As suggested by Cor Ligthert, i've created a simpler sample, with the same
> problem; this is the full source code,
> so everyone can try itself:
>
> Access database "dati.mdb":
> Tables:
> "myTable"
> Fields:
> fNumber Numeric
> fString VarChar(50)
> No primary keys defined.
> Stored Procedures:
> "qry_Ins":
> PARAMETERS [@fNumber] Long, [@fString] Text ( 255 );
> INSERT INTO myTable ( fNumber, fString )
> VALUES ([@fNumber], [@fString]);
>
>
> C# Project: Only 1 WebForm (WebForm1.aspx)
> //////////////////////////////////////////
> // Code Start
> //////////////////////////////////////////
>
> private void Page_Load(object sender, System.EventArgs e)
> {
>
> OleDbConnection conn = new
> OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
> "Data Source=" + Server.MapPath("dati.mdb") + ";");
>
> conn.Open();
>
> OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM myTable",
conn);
> DataSet ds = new DataSet();
>
> // The table is initially empty so ds has no rows
> da.Fill(ds, "myTable");
>
>
> OleDbCommand upCmd = new OleDbCommand("qry_Ins", conn);
> upCmd.CommandType = CommandType.StoredProcedure;
>
> upCmd.Parameters.Add("@fNumber", OleDbType.Integer, 0, "fNumber");
> upCmd.Parameters.Add("@fString", OleDbType.VarChar, 50, "fString");
>
>
> da.InsertCommand = upCmd;
>
> int i = 1;
> while (i<=20)
> {
> ds.Tables["myTable"].Rows.Add(new object[] {i, "data_" + i});
> i++;
> }
>
> da.Update(ds, "myTable");
>
> conn.Close();
> conn = null;
>
> }
> //////////////////////////////////////////
> // Code End
> //////////////////////////////////////////
>
> This is the output in the database after 1 execution of the above code:
>
> fNumber fString
> 1 data_1
> 1 data_2
> 1 data_3
> 1 data_4
> 1 data_5
> 1 data_6
> 1 data_7
> 1 data_8
> 1 data_9
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_1
> 1 data_2
>
> As visible, fNumber is always 1, and fString is truncated to 6 chars.
> So, how to fix? It's a BUG???
>
>
>
>
| |
|
| yes
"Jeff Dillon" <jeff@removeemergencyreporting.com> ha scritto nel messaggio
news:%23dTnzlw1EHA.3596@TK2MSFTNGP12.phx.gbl...
> And "varchar" in an Access database? You meant Text, correct?
>
> Jeff
> "joun" <joun@nospam.com> wrote in message
> news:Rf0rd.58489$Ni.2006399@twister1.libero.it...
> conn);
>
>
| |
|
| Yes, copy & paste.
"Jeff Dillon" <jeff@removeemergencyreporting.com> ha scritto nel messaggio
news:O8Kgkkw1EHA.1652@TK2MSFTNGP11.phx.gbl...
> What do you mean "output of the database". How are you printing out the
> values below? I'm assuming you've opened the database in Access, and
> widened the display grid columns?
>
> Jeff
>
> "joun" <joun@nospam.com> wrote in message
> news:Rf0rd.58489$Ni.2006399@twister1.libero.it...
> conn);
>
>
|
|
|
|
|