S
sarunasz
Guest
Hello,
I'm trying to learn from this video:
When I try execute my code,I always got mistake "System.Data.SqlClient.SqlException: 'Incorrect syntax near 'value'.'
"
The program stops at this line "cmd.ExecuteNonQuery();"
Maybe somebody can give suggest How solve this problem?
My code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string conString = "Data Source=SARUNAS-PC\\dragunai;Initial Catalog=connectionDB;Integrated Security=True";
private void Label1_Click(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
string q = "INSERT INTO Test(ID,name) value('" + txtID.Text.ToString() + "','" + txtname.Text.ToString() + "')";
SqlCommand cmd = new SqlCommand(q, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Connection made Successfully");
}
con.Close();
}
}
}
Continue reading...
I'm trying to learn from this video:
When I try execute my code,I always got mistake "System.Data.SqlClient.SqlException: 'Incorrect syntax near 'value'.'
"
The program stops at this line "cmd.ExecuteNonQuery();"
Maybe somebody can give suggest How solve this problem?
My code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string conString = "Data Source=SARUNAS-PC\\dragunai;Initial Catalog=connectionDB;Integrated Security=True";
private void Label1_Click(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
string q = "INSERT INTO Test(ID,name) value('" + txtID.Text.ToString() + "','" + txtname.Text.ToString() + "')";
SqlCommand cmd = new SqlCommand(q, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Connection made Successfully");
}
con.Close();
}
}
}
Continue reading...