CS1503 C#参数1:无法转换为'字符串'到' System.Data.SqlClient.SqlCommand'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataEntry
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection(@"C:\USERS\ARUNKUMARREDDY\DOCUMENTS\Cons.accdb");
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dataSet1.callsheet'
// table. You can move, or remove it, as needed.
this.callsheetTableAdapter.Fill(this.dataSet1.callsheet);
}
private void button2_Click(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(@"Insert into Aplomb (ID,Vendor
Name,Consultancy Name,Email ID,Phone No,Role,
Client,Job Location,Date)values('"+textBox1.Text+ "','" +
textBox2.Text + "','" + textBox3.Text + "','" +
textBox4.Text + "','" + textBox5.Text + "','" +
textBox6.Text + "','" + textBox7.Text + "')con");
sda.SelectCommand.ExecuteNonQuery();
con.Close();
MessageBox.Show("saved successfuly");
}
}
}
答案 0 :(得分:0)
这里有一些代码可以帮助你
using (SqlConnection conn = new SqlConnection("connectionString"))
{
// Open Connection
conn.Open();
// Define Sql Command
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SQL Query";
cmd.Connection = conn;
// Your Adapter, Editted you are insert not get Data Comment
//SqlDataAdapter adapter = new SqlDataAdapter();
//adapter.SelectCommand = cmd;
cmd.ExecuteNonQuery();
}
但是你仍然应该正确检查你的代码......