Answered error of syntax

  • 2 aprilie 2012 17:10
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using MSTSCLib;
    using System.Data.SqlClient;
    using System.Data.OleDb;


    namespace SampleRDC
    {
        public partial class Form1 : Form
        {
            private OleDbConnection myCon;
          //  string str = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Prashant\Desktop\SampleRDC\Database2.accdb;User Id=admin;Password=;";
            //string query;
     
            public Form1()
            {
                 InitializeComponent();
                 myCon = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Prashant\Desktop\SampleRDC\Database2.accdb;User Id=admin;Password=;User Id=admin;Password=;");
                InitializeComponent();
            }
          
            


            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                     OleDbCommand cmd = new OleDbCommand();
                myCon.Open();
                cmd.Connection = myCon;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText="INSERT INTO Records(Server, UserName, Password) Values ('" + txtServer.Text + "' , '" + txtUserName.Text + "' , '" + txtPassword.Text + "')";




                cmd.ExecuteNonQuery();
                myCon.Close();
                     }
                    /*
                    rdp.Server = txtServer.Text;
                    rdp.UserName = txtUserName.Text;


                    IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
                    secured.ClearTextPassword = txtPassword.Text;
                    rdp.Connect();
                    */
                
                catch (Exception Ex)
                {
                  //  MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + txtServer.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    MessageBox.Show(Ex.Message);
                }
            }


            private void button2_Click(object sender, EventArgs e)
            {
                try
                {
                    // Check if connected before disconnecting
                    if (rdp.Connected.ToString() == "1")
                        rdp.Disconnect();
                }
                catch (Exception Ex)
                {
                    MessageBox.Show("Error Disconnecting", "Error disconnecting from remote desktop " + txtServer.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }


          


          
        }
    }

Toate mesajele

  • 2 aprilie 2012 17:11
     
     
    please remove this error...
  • 2 aprilie 2012 17:37
     
     
    You dont need help?

    Mitja

  • 4 aprilie 2012 09:39
    Moderator
     
     Răspuns
    please remove this error...
    Hi prashant,
    The syntax error message means that your insert command text has syntax error.
    Please debug your code, get the command Text and run it in the access Query Tools (click Create->Query Desing->right click and select SQL View), then you will get more details of the error.
    In addition, I suggest you use a parameterized SQL statement. If you still have the error, could you please show us the entire error message and the table structure?
    Best Regards,

    Bob Wu [MSFT]
    MSDN Community Support | Feedback to us