繁体   English   中英

CS1503 C# 参数 1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand”

[英]CS1503 C# Argument 1: cannot convert from 'string' to 'System.Data.SqlClient.SqlCommand'

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");
    }
  }
}

这里有一些代码可能对你有帮助

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();
}

但是你仍然应该正确检查你的代码......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM