首页上一页 1 下一页尾页 3 条记录 1/1页
例子
发表在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;
}
}
}
这是这么回事出现在哪里?代码:
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;
}
}
}