Hello
I want to transfer data from a access table to a sql table. Simple by clicking a button.
first off all i set up and OleDbConnection and a SqlConnection in my web.config file.
This is the code i use in a b button method for transfer data for 1 tab
le.
protected void clickBtn1(object sender, EventArgs e)
{
OleDbConnection conn = null;
string sLectorId = "";
try
{
// Ophalen van de connectiestring
string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString"].ToString();
conn = new OleDbConnection(connString);
// Aanmaken commando
string sql =
"SELECT * FROM tblLector";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
// databinden!!
while (reader.Read())
{
int lectorId = reader.GetOrdinal("LECTORID");
if (!reader.IsDBNull(lectorId))
sLectorId = reader.GetString(lectorId);
tbxTest.Text = sLectorId;
}
//sluiten connectie
conn.Close();
}
catch(Exception ex)
{
lblFout.Text = ex.Message;
}
try
{
string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString2"].ToString();
SqlConnection conn2 = new SqlConnection(connString);
// defineren sql
string sql =
"INSERT INTO tblLector(LECTORID) " +
"VALUES( @lectorid )";
SqlCommand cmd = new SqlCommand(sql, conn2);
cmd.Parameters.AddWithValue("@lectorid",sLectorId );
// connectie opene, commando uitvoeren en connectie sluiten
conn2.Open();
cmd.ExecuteNonQuery();
conn2.Close();
}
catch ( Exception ex )
{
lblFout.Text = ex.Message;
}
}
When application starts up and I press the button its says in the error box "specified cast is not valid".
I feel it's the right way to do it.
Can somebody helps me plx.
Thx in advance
GRTZ
I want to transfer data from a access table to a sql table. Simple by clicking a button.
first off all i set up and OleDbConnection and a SqlConnection in my web.config file.
This is the code i use in a b button method for transfer data for 1 tab
le.
protected void clickBtn1(object sender, EventArgs e)
{
OleDbConnection conn = null;
string sLectorId = "";
try
{
// Ophalen van de connectiestring
string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString"].ToString();
conn = new OleDbConnection(connString);
// Aanmaken commando
string sql =
"SELECT * FROM tblLector";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
// databinden!!
while (reader.Read())
{
int lectorId = reader.GetOrdinal("LECTORID");
if (!reader.IsDBNull(lectorId))
sLectorId = reader.GetString(lectorId);
tbxTest.Text = sLectorId;
}
//sluiten connectie
conn.Close();
}
catch(Exception ex)
{
lblFout.Text = ex.Message;
}
try
{
string connString = ConfigurationManager.ConnectionStrings["RandapparatuurConnectionString2"].ToString();
SqlConnection conn2 = new SqlConnection(connString);
// defineren sql
string sql =
"INSERT INTO tblLector(LECTORID) " +
"VALUES( @lectorid )";
SqlCommand cmd = new SqlCommand(sql, conn2);
cmd.Parameters.AddWithValue("@lectorid",sLectorId );
// connectie opene, commando uitvoeren en connectie sluiten
conn2.Open();
cmd.ExecuteNonQuery();
conn2.Close();
}
catch ( Exception ex )
{
lblFout.Text = ex.Message;
}
}
When application starts up and I press the button its says in the error box "specified cast is not valid".
I feel it's the right way to do it.
Can somebody helps me plx.
Thx in advance
GRTZ