已有57人关注
例子
发表在C#图书答疑 2012-01-28
是否精华
版块置顶:
大家帮我看看,C#编程全能词典里-开发-实例中心-实用工具-个人工具-个人通讯录的代码看看:运行添加出现未能找到存储过程'frmInsert'
这是这么回事出现在哪里?代码:
 private void FrmTx_Load(object sender, EventArgs e)
        {
            //getTreeName();
        }
        public void getTreeName()
        {
            SqlConnection con = new SqlConnection("server=PC2011061719WKA;uId=sa;pwd=sa;database=Hb");
            con.Open();
            SqlCommand com = new SqlCommand("select * from tb_Contact");
            SqlDataReader dr = com.ExecuteReader();
            treeView1.Nodes.Clear();
            TreeNode tv = treeView1.Nodes.Add("A", "朋友信息", 0, 1);
            while (dr.Read())
            {
                tv.Nodes.Add("A", "姓名:" + dr[1].ToString(), 0, 1);
            }
            dr.Close();
            com.Connection.Close();
            con.Close();
            treeView1.ExpandAll();
        }
        public int intFalg = 0;
        private void treeView1_AfterSelect(object sender, TreeViewCancelEventArgs e)
        {
            if (treeView1.SelectedNode.Text != "")
            {
                getInfo(treeView1.SelectedNode.Text.Substring(3));
                if (txtName.Text != "")
                {
                    txtName.Enabled = false;
                    intFalg = 1;
                }

            }
        }
        public void getInfo(string strName)
        {
            SqlConnection con = new SqlConnection("server=PC2011061719WKA;uid=sa;pwd=sa;database=Hb");
            con.Open();
            SqlCommand com = new SqlCommand("select * from tb_Contact where FrmName = '" + strName + "'", con);
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                txtName.Text = dr[1].ToString();
                txtPhone.Text = dr[2].ToString();
                txtQQ.Text = dr[3].ToString();
                txtShortPhone .Text= dr[4].ToString();
                txtOther.Text = dr[5].ToString();
                txtNote .Text= dr[6].ToString();

            }
            dr.Close();
            com.Connection.Close();
            con.Close();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (intFalg == 1)
            {
                foreach (object ct in Controls)
                {
                    if (ct.GetType().ToString() == "System.Windows.Forms.TextBox")
                    {
                        TextBox tx = (TextBox)ct;
                        tx.Text = "";
                        tx.Enabled = true;
                    }

                } intFalg = 0;
            }
            else
            {
                if (txtName.Text == "")
                {
                    MessageBox.Show("姓名不能为空");
                    txtName.Focus();
                    return;

                }
                if (txtQQ.Text == "" && txtPhone.Text == "")
                {
                    MessageBox.Show("联系电话不能都为空");
                    if (txtPhone.Text == "")
                    {
                        txtPhone.Focus();
                        return;
                    }

                }
            }


            SqlConnection con = new SqlConnection("server=PC2011061719WKA;uid=sa;pwd=sa;database=Hb");
            con.Open();
            SqlCommand com = new SqlCommand();
            com.Connection = con;
            com.CommandText = "frmInsert";
            com.CommandType = CommandType.StoredProcedure;
            com.Parameters.Add("@frmName", SqlDbType.VarChar, 50);
            com.Parameters.Add("@frmPhone", SqlDbType.VarChar,11);
            com.Parameters.Add("@frmShortPhone", SqlDbType.VarChar, 50);
            com.Parameters.Add("@frmQQ", SqlDbType.VarChar, 50);
            com.Parameters.Add("@frmOther", SqlDbType.VarChar, 50);
            com.Parameters.Add("@frmNote", SqlDbType.VarChar, 50);
            com.Parameters["@frmName"].Value = txtName.Text;
            com.Parameters["@frmPhone"].Value = txtPhone.Text;
            com.Parameters["@frmQQ"].Value = txtQQ.Text;
            com.Parameters["@frmShortPhone"].Value = txtShortPhone.Text;
            com.Parameters["@frmOther"].Value = txtOther.Text;
            com.Parameters["@frmNote"].Value = txtNote.Text;
            SqlParameter sqlpar = com.Parameters.Add("@frmReturn", SqlDbType.Bit, 1);
            sqlpar.Direction = ParameterDirection.Output;
            com.ExecuteNonQuery();
            string strFalg = com.Parameters["@frmReturn"].Value.ToString();
            if (strFalg == "True")
            {
                MessageBox.Show("添加成功");
                foreach (object ct in Controls)
                {
                    if (ct.GetType().ToString() == "System.Windows.Forms.TextBox")
                    {
                        TextBox tx = (TextBox)ct;
                        tx.Text = "";
                        tx.Enabled = true;

                    }
                }
                getTreeName();
            }
            else { MessageBox.Show("添加失败"); }
            con.Close();
        }

        private void btnModif_Click(object sender, EventArgs e)
        {
            if (intFalg == 0)
            {
                MessageBox.Show("请选择修改条件");
                return;
            }
            else
            {
                SqlConnection con = new SqlConnection("server=PC2011061719WKA;uid=sa;pwd=sa;database=Hb");
                con.Open();
                SqlCommand com = new SqlCommand();
                com.Connection = con;
                com.CommandText = "frmUpdate";
                com.CommandType = CommandType.StoredProcedure;



                com.Parameters.Add("@frmPhone", SqlDbType.VarChar, 20);
                com.Parameters["@frmShortPhone"].Value = txtShortPhone.Text;

                com.Parameters.Add("@frmPhone", SqlDbType.VarChar, 20);
                com.Parameters["@frmPhone"].Value = txtPhone.Text;

                com.Parameters.Add("@frmQQ", SqlDbType.VarChar, 20);
                com.Parameters["@frmQQ"].Value = txtQQ.Text;

                com.Parameters.Add("@frmOther", SqlDbType.VarChar, 50);
                com.Parameters["@frmOther"].Value = txtOther.Text;

                com.Parameters.Add("@frmNone", SqlDbType.VarChar, 50);
                com.Parameters["@frmNone"].Value = txtNote.Text;

                com.Parameters.Add("@frmName", SqlDbType.VarChar, 50);
                com.Parameters["@frmName"].Value = txtName.Text;

                SqlParameter sqlpar = com.Parameters.Add("@frmReturn", SqlDbType.Bit, 1);
                sqlpar.Direction = ParameterDirection.Output;
                com.ExecuteNonQuery();
                string strFalg = com.Parameters["@frmReturn"].Value.ToString();
                if (strFalg == "True")
                {
                    MessageBox.Show("修改成功");
                    foreach (object ct in Controls)
                    {
                        if (ct.GetType().ToString() == "System.Windows.Forms.TextBox")
                        {
                            TextBox tx = (TextBox)ct;
                            tx.Text = "";
                            tx.Enabled = true;
                        }
                    }//eind
                    getTreeName();
                    intFalg = 0;
                }//
                else
                {
                    MessageBox.Show("修改失败");
                    intFalg = 0;
                }
                con.Close();

            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                MessageBox.Show("请选择要删除的信息");
                return;
            }
            else
            {
                SqlConnection con = new SqlConnection("server=PC2011061719WKA;uid=sa;pwd=sa;database=Hb");
                con.Open();
                SqlCommand com = new SqlCommand("delete from tb_Contact where FrmName='" + txtName.Text.Trim() + "'", con);
                int i = (int)com.ExecuteNonQuery();
                if (i != 0)
                {
                    MessageBox.Show("删除成功");
                    getTreeName();
                    foreach (object ct in Controls)
                    {
                        if (ct.GetType().ToString() == "System.Windows.Forms.TextBox")
                        {
                            TextBox tx = (TextBox)ct;
                            tx.Text = "";
                            tx.Enabled = true;
                        }
                    }//eind
                    intFalg = 0;
                }
            }
        }

       
分享到:
精彩评论 3
东方_mrkj
学分:0 LV1
2012-01-30
沙发
读者你好:
    可以到数据库中确认“frmInsert”这个存储过程名是否存在,问题应该出在这里。
坚持就是胜利
学分:0 LV1
2012-02-15
板凳
存储过程写进去,还是写进去“为过程或函数 frmInsert 指定的参数太多”我找了很长时间就是没有找出那里出错
坚持就是胜利
学分:0 LV1
2012-02-15
地板
存储过程代码对吗?大家帮我看看我只加了两个数据。就是姓名和号码,其他数据我都删除了
ALTER PROCEDURE [dbo].[frmInsert]
-- Add the parameters for the stored procedure here
(@Name  varChar(50), 
@Phone varChar (11))
    
AS INSERT INTO [tb_Contact] (
      Name,
      Phone) 
 VALUES (
       @Name,
       @Phone)
首页上一页 1 下一页尾页 3 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照