2017-10-15 1 views
-4

erwartet erhalte ich get oder AccessorA erhalten oder Set-Accessor

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\KARTHICK\Documents\test.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"); 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      con.Open(); 
      SqlCommand cmd = con.CreateCommand(); 
      cmd.CommandType = CommandType.Text; 
      cmd.CommandText = "insert into table1 values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')"; 
      cmd.ExecuteNonQuery(); 
      con.Close(); 

      MessageBox.Show("record inserted successfully"); 
     } 
     public void display 
     { 
      con.Open(); 
      SqlCommand cmd = con.CreateCommand(); 
      cmd.CommandType = CommandType.Text; 
      cmd.CommandText = "select * from table1"; 
      cmd.ExecuteNonQuery(); 
      DataTable dt=new DataTable(); 
      SqlDataAdapter dt= new SqlDataAdapter(cmd); 
      da.fill(dt); 
      con.Close(); 
     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
     display(); 
     } 
    } 
} 
+3

definiert Sie fehlen '()' nach dem Funktionsnamen auf 'public void display' –

+0

Können Sie einige Beschreibungen, um Ihren Code hinzufügen? –

+1

Fehler bei welcher Zeile? BTW, schon mal von [sql injection attacks] gehört (https://msdn.microsoft.com/en-us/library/ff648339.aspx)? –

Antwort

0

Sie haben einige Fehler vorbehalten gesetzt:

  1. hinzufügen () bis Ende public void display

  2. doppelte variable genannt dt bei SqlDataAdapter dt= new SqlDataAdapter(cmd);

  3. da Variable nicht auf da.fill(dt);
Verwandte Themen