需要未提供的参数

需要未提供的参数

本文介绍了参数化查询'((@Account_No nvarchar(4000),@ Account_title nvarchar(4000),@ Entry)需要未提供的参数'@Account_type'.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void btnsave_Click(object sender, EventArgs e)
        {
            String query = "insert into Accounts(Account_No,Account_title,Entry_Date,Initial_Deposite,Account_type,Account_Nature,Postal_Code,District,City,Name,Father_name,Husband_name)values(@Account_No,@Account_title,@Entry_Date,@Initial_Deposite,@Account_type,@Account_Nature,@Postal_Code,@District,@city,@Name,@Father_name,@Husband_name,@Occupation,@Mobile,@CNIC)";
            SqlCommand cmd = new SqlCommand(query, cn);
            cmd.Prepare();
            cmd.Parameters.AddWithValue("@Account_No", txtaccount1.Text);
            //cmd.Parameters.Add("@Account_No", System.Data.SqlDbType.NVarChar).Value = txtaccount1.Text;
            cmd.Parameters.AddWithValue("@Account_title", txtaccounttitle.Text);
           // cmd.Parameters.Add("@Account_title", System.Data.SqlDbType.NVarChar).Value = txtaccounttitle.Text;
            cmd.Parameters.AddWithValue("@Entry_Date", dateTimePicker1.Value.Date);
            cmd.Parameters.AddWithValue("@Initial_Deposite", txtinitial.Text);
            //cmd.Parameters.AddWithValue("@Account_type", txtaccounttype.Text);
            cmd.Parameters.AddWithValue("@Account_Nature", txtaccountnature.Text);
            cmd.Parameters.AddWithValue("@Account_type",cboaccounttype.SelectedValue);

            cmd.Parameters.AddWithValue("@Postal_code", txtpostal.Text);
            cmd.Parameters.AddWithValue("@City", cbocity.SelectedValue);
            cmd.Parameters.AddWithValue("@District", cbodistrict.SelectedValue);

            cmd.Parameters.AddWithValue("@Name", txtname1.Text);
            cmd.Parameters.AddWithValue("@Father_name", txtfather1.Text);
            cmd.Parameters.AddWithValue("@Husband_name", txthusband1.Text);
            cmd.Parameters.AddWithValue("@Occupation", txtoccupation1.Text);
            cmd.Parameters.AddWithValue("@Mobile", txtmobile1.Text);
            cmd.Parameters.AddWithValue("@CNIC", txtcnic1.Text);
            cmd.ExecuteNonQuery();
            MessageBox.Show("record stored");

        }
            }
        }

推荐答案

cmd.Parameters.AddWithValue("@Account_type",cboaccounttype.SelectedValue ?? DBNull.Value);


这篇关于参数化查询'((@Account_No nvarchar(4000),@ Account_title nvarchar(4000),@ Entry)需要未提供的参数'@Account_type'.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 05:22