TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Israel
700
1.3k
215.9k
Same code for MSACCESS and SQLSERVER but giving error
Dec 30 2019 7:32 AM
Hi, as you see I have two pieces of codes transfering datas Table1 to Table2.
1) The first piece is transfering datas using MSAccess’s Table. It doing well the job.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
namespace
WindowsFormsApplication1
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e)
{
string
myConnectionString;
myConnectionString = @
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Copy_table_to_table\WindowsFormsApplication1\App_Datas\test.mdb;Persist Security Info=False"
;
using
(var con =
new
OleDbConnection())
{
con.ConnectionString = myConnectionString;
con.Open();
using
(var cmd =
new
OleDbCommand())
{
cmd.Connection = con;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @
"INSERT INTO test2 IN 'C:\Copy_table_to_table\WindowsFormsApplication1\App_Datas\test.mdb' "
+ @
"SELECT A,B,C FROM test1"
;
cmd.ExecuteNonQuery();
}
con.Close();
}
Console.WriteLine(
"Done."
);
}
}
}
2) The Segond piece is transfering from Table1 to Table2 uing SQLSERVER’s Table. Unfortunatly, its stucking giving this error message: Incorrect syntax near the keyword 'IN'
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Data;
using
System.Data.SqlClient;
namespace
WindowsFormsApplication1
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
SqlConnection conn =
new
SqlConnection(
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf;Integrated Security = True;Integrated Security = True"
);
SqlCommand comm;
SqlDataAdapter da;
string
connstr = @
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename=C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf;Integrated Security = True;Integrated Security = True"
;
private
void
button1_Click(
object
sender, EventArgs e)
{
string
myConnectionString;
myConnectionString =
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf; Integrated Security = True; Integrated Security = True"
;
{
conn =
new
SqlConnection(
"Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = C:\\Copy_table_to_table\\WindowsFormsApplication1\\test.mdf; Integrated Security = True; Integrated Security = True"
);
if
(conn.State != ConnectionState.Open)
conn.Open();
using
(var cmd =
new
SqlCommand())
{
cmd.Connection = conn;
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = @
"INSERT INTO test2 IN 'C:\Copy_table_to_table\WindowsFormsApplication1\test.mdf' "
+ @
"SELECT A,B,C FROM test1"
;
cmd.ExecuteNonQuery();
}
}
Console.WriteLine(
"Done."
);
conn.Close();
}
}
}
Reply
Answers (
1
)
MVC core Online Exam Application
where i get best complete tutorial of ML.NET ????