insert into mst_report_dtls(report_name,url_path,login_id,pwd,domain,amd_date,amd_user_id)
 values ('Contractwise_statistics','http://192.168.22.11/ReportServer?/TradingReport/Contractwise_statistics','dbadmin','1nPrPgqv5UIpU4SYnGddJw==','ace',getdate(),1)

Above statement i used to run from backend.
Now i have developed a front end
While running the code it gives me SQL Exception
Following is my code

namespace Ace_System_test
{
    public partial class Admin_CRMReport : Form
    {
        
        SqlConnection connstr = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["database"]);
        
        public Admin_CRMReport()
        {
            InitializeComponent();
        }

        private void Admin_CRMReport_Load(object sender, EventArgs e)
        {
            
            DataTable dt = new DataTable();
            string sqlquery = "select url_path from mst_Report_Folder_Path";
            try
            {

                connstr.Open();     //Open the Connection
                using (SqlCommand cmd = new SqlCommand(sqlquery, connstr))
                {
                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        dt = new DataTable();
                        dt.Load(dr);
                    }
                }

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    foldernamecomboBox.Items.Add(dt.Rows[i]["url_path"]);
                }
                foldernamecomboBox.SelectedIndex = 0;




            }
            catch (Exception err)
            {
                MessageBox.Show("Error Message : " + err.Message);
            }
            finally
            {
                connstr.Close();
            }
        }

        private void buttonAdd_Report_Click(object sender, EventArgs e)
        {
            string urlpath = "";
            string login = "";
            string pwd = "";
            string domain = "";
            string path = Convert.ToString(foldernamecomboBox.SelectedItem);
            string report_name = textBoxReportname.Text;
            string pathquery = "select * from mst_Report_Folder_Path where url_path = '" + path + "'";
            string date = "getdate()";
            int i = 1;
            
            connstr.Open();
            SqlCommand cmd1 = new SqlCommand(pathquery, connstr);
            cmd1.CommandType = CommandType.Text;
            SqlDataReader dtreader = cmd1.ExecuteReader();
            while (dtreader.Read())
            {
                urlpath = Convert.ToString(dtreader[0]);
                login = Convert.ToString(dtreader[1]);
                pwd = Convert.ToString(dtreader[2]);
                domain = Convert.ToString(dtreader[3]);
            }
            dtreader.Close();
            string final_path = urlpath + report_name;

            cmd1.CommandText = "insert into acees.dbo.mst_report_dtls(report_name,url_path,login_id,pwd,domain,amd_date,amd_user_id) values(@report_name, @url_path, @login_id, @pwd, @domain, @amd_date,@amd_user_id)";
            cmd1.Parameters.AddWithValue("@report_name", report_name);
            //@domain, @amd_date,@amd_user_id
            cmd1.Parameters.AddWithValue("@url_path", final_path);
            cmd1.Parameters.AddWithValue("@login_id", login);
            cmd1.Parameters.AddWithValue("@pwd", pwd);
            cmd1.Parameters.AddWithValue("@domain", domain);
            cmd1.Parameters.Add("@amd_date", SqlDbType.DateTime, 60, date); [B]I think it giving error at this point[/B]
            cmd1.Parameters.AddWithValue("@amd_user_id", i);
            cmd1.ExecuteNonQuery();
            MessageBox.Show("Data inserted sucessfully");

        }

        private void buttonAdd_Rep_Module_Cmd_Click(object sender, EventArgs e)
        {

        }
    }
}

If getdate() is coming from the database, don't use a parameter with it; just hard-code it like what is in your example. You can use a parameter with everything else.

This article has been dead for over six months. Start a new discussion instead.