"INSERT INTO Customer_Apartment_Details( ApartmentID, Date of occupying,
The problem seems to be the spaces in the column name
Try to use [], like [ApartmentID], [Date of occupying],
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword 'of'.'
I am getting the above mentioned error whenever I try to run my form. The error highlights this statement: cmd.ExecuteNonQuery();
Here's my code.
namespace RegistrationForm
{
public partial class AptId : Form
{
public AptId()
{
InitializeComponent();
}
void Connection()
{
string cs = ConfigurationManager.ConnectionStrings["Data Source=DESKTOP-0R6CP8V;Initial Catalog=Apartment;Persist Security Info=True;User ID=sa;Password=*******"].ConnectionString;
SqlConnection conn = null;
using (conn = new SqlConnection(cs))
{
string queryString = "select Rent from Customer_Apartment_Details where Rent>150";
SqlCommand command = new SqlCommand(queryString, conn);
conn.Open();
String datavalue = command.ExecuteScalar().ToString();
MessageBox.Show(datavalue);
}
}
void insertData()
{
SqlConnection sqlConnection = new SqlConnection("Data Source=DESKTOP-0R6CP8V;User ID=sa;Password=*******;Initial Catalog=Apartment;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
string query = "INSERT INTO Customer_Apartment_Details( ApartmentID, Date of occupying, Rent, Paymode) VALUES ( '" + apartmentIDTextBox.Text + "','" + date_of_occupyingTextBox.Text + "','" + rentTextBox.Text + "','" + paymodeTextBox.Text + "')";
SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, sqlConnection);
sqlConnection.Open();
**cmd.ExecuteNonQuery();**
sqlConnection.Close();
}
public void button1_Click(object sender, EventArgs e)
{
int num = int.Parse(apartmentIDTextBox.Text);
switch (num)
{
case 1:
rentTextBox.Text = "280";
break;
case 2:
rentTextBox.Text = "250";
break;
case 3:
rentTextBox.Text = "300";
break;
case 4:
rentTextBox.Text = "300";
break;
case 5:
rentTextBox.Text = "270";
break;
case 6:
rentTextBox.Text = "270";
break;
case 7:
rentTextBox.Text = "220";
break;
case 8:
rentTextBox.Text = "200";
break;
case 9:
rentTextBox.Text = "200";
break;
case 10:
rentTextBox.Text = "200";
break;
default:
MessageBox.Show("Enter your apartment ID");
break;
}
}
public void button2_Click(object sender, EventArgs e)
{
insertData();
Rent rent = new Rent(this);
rent.ShowDialog();
}
}
Can someone please help me out solving this error?
Thanks in advance
"INSERT INTO Customer_Apartment_Details( ApartmentID, Date of occupying,
The problem seems to be the spaces in the column name
Try to use [], like [ApartmentID], [Date of occupying],
System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword 'into'.'
private void button1_Click(object sender, EventArgs e)
{
Con.Open();
string query = "inseret into DoctorTbl Values(" + Docid.Text + ", ' " + DocName.Text + "', " + Docexp.Text + "'," + DocPass.Text + "')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Doctor Successfully Added");
Con.Close();
}
System.Data.SqlClient.SqlException: 'Incorrect syntax near the keyword 'into'.'
0No comments