如何摆脱将两个面板控制数据保存到数据库时出现的问题 [英] How to get rid of the problem occured when saving two panel control data to database

查看:71
本文介绍了如何摆脱将两个面板控制数据保存到数据库时出现的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hai all

i已经来到这里

i有一个文本框和一个按钮所以如果我在文本框中点击一个应该出现一个带控制台的面板控件

因此,如果我在文本框中输入2,则应显示其中包含表格的两个面板控件

到此处工作正常时将单个表值保存到数据库时,使用storedprocesure插入到此处插入两个面板控件时也很好或三个表与数据到数据库这里问题来了



他们正在保存像

for ex在数据库firstname那里他们插入像ravi ,ram,raj in firstname字段

不喜欢ram和raj必须插入下一条记录中它们保存在一条记录中

以下是我的代码plz helpme

hai all
i have strucked here
i have atextbox and one button so if i click one in textbox one panelcontrol with table should appear
so if i enter 2 in textbox two panelcontrols with tables in it should be displayed
up to here working fine when saving single table valuues to database they are inserting using storedprocesure up to here also fine when inserting two panelcontrols or threepanel with tables data to database here problem coming

they are saving like
for ex in database firstname is there they are inserting like ravi,ram,raj in firstname field
not like ram and raj have to be insert in next records they are saving in one record
below is my code plz helpme

public partial class addnewprac : System.Web.UI.Page
{
    int count;
    
    protected void Page_Load(object sender, EventArgs e)
    {
    
    }
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        count = Convert.ToInt32(TextBox1.Text);
        for (int i = 0; i < count; i++)
        {
            // int index = Panel1.Controls.OfType<textbox>().ToList().Count + 1;
            
            Table tbldynamic = new Table();
            tbldynamic.ID = "tbl" + i.ToString();
            TableCell tc = new TableCell();
            TableCell tc1 = new TableCell();
            TableRow tr = new TableRow();
            Label lbl = new Label();
            
            lbl.ID = "lbluid";
            lbl.Text = "Studentfirstname:";
            tc.Controls.Add(lbl);
            
            TextBox userid = new TextBox();
            userid.ID = "txtuid"+i;
            tc1.Controls.Add(userid);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label lblName = new Label();
            lblName.ID = "lblName";
            lblName.Text = "Studentlastname:";
            tc.Controls.Add(lblName);
            TextBox txtName = new TextBox();
            txtName.ID = "txtNamea"+i;
            tc1.Controls.Add(txtName);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label goingsc = new Label();
            goingsc.ID = "lblEmaila";
            goingsc.Text = "Going to school:";
            tc.Controls.Add(goingsc);
            CheckBox chk = new CheckBox();
            chk.ID = "chkaa"+i;
            chk.Text = "yes";
            tc1.Controls.Add(chk);
            
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label lblEmailab = new Label();
            lblEmailab.ID = "lblEmail";
            lblEmailab.Text = "SCHOOLNAME:";
            tc.Controls.Add(lblEmailab);
            TextBox schoolname = new TextBox();
            schoolname.ID = "sname"+i;
            tc1.Controls.Add(schoolname);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
            tc = new TableCell();
            tc1 = new TableCell();
            tr = new TableRow();
            Label grade = new Label();
            grade.ID = "lblEmailabc";
            grade.Text = "grade:";
            tc.Controls.Add(grade);
            DropDownList dpd = new DropDownList();
            ListItem[] items = new ListItem[3];
            items[0] = new ListItem("A Grade", "1");
            items[1] = new ListItem("B Grade", "2");
            
            items[2] = new ListItem("C Grade", "3");
            dpd.Items.AddRange(items);
            dpd.DataBind();
            dpd.ID = "select"+i;
            
            tc1.Controls.Add(dpd);
            tr.Cells.Add(tc);
            tr.Cells.Add(tc1);
            tbldynamic.Rows.Add(tr);
                        
            Panel1.Controls.Add(tbldynamic);
        }
    }

    protected void btnSubmit_click(object sender, EventArgs e)
    {
        TextBox firstname = (TextBox)Panel1.FindControl("txtuid");
        
        TextBox lastname = (TextBox)Panel1.FindControl("txtNamea");
        CheckBox chkk = (CheckBox)Panel1.FindControl("chkaa");
        TextBox txttt = (TextBox)Panel1.FindControl("sname");
        DropDownList dda = (DropDownList)Panel1.FindControl("select");
        Response.Write(firstname.Text);
        Response.Write(lastname.Text);
        Response.Write(chkk.Text);
        Response.Write(txttt.Text);
        Response.Write(dda.Text);
        SqlConnection con = new SqlConnection("Data Source=HOME;Initial Catalog=login;Integrated Security=True");
        
        SqlCommand cmd = new SqlCommand("[student info]", con);
        cmd.CommandType = System.Data.CommandType.StoredProcedure;
        con.Open();
        cmd.Parameters.AddWithValue("@sname", firstname.Text);
        cmd.Parameters.AddWithValue("@slname", lastname.Text);
        cmd.Parameters.AddWithValue("@gsch", chkk.Text);
        cmd.Parameters.AddWithValue("@ssname", txttt.Text);
        cmd.Parameters.AddWithValue("@sgr", dda.SelectedItem.Text);
        cmd.ExecuteNonQuery();
        
        con.Close();    
    }



我存储的流程是


my stored procesure is

USE [login]
GO

/****** Object: StoredProcedure [dbo].[student info] Script Date: 11/03/2015 15:06:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE procedure [dbo].[student info]
(
    @sname nvarchar(50),
    @slname nvarchar(50),
    @gsch bit,
    @ssname nvarchar(50),
    @sgr nvarchar(50)
)
as
begin

    insert into studentdetails values(@sname,@slname,@gsch,@ssname,@sgr)
end
GO



任何身体帮助

感谢和问候

raviram


any body helpme
thank and regards
raviram

推荐答案

你的问题很难解释,但我是试图在这里猜测你的问题。



你需要在循环中调用存储过程。

1.在提交按钮单击,找到表的数量

2.遍历它们。

3.在循环中,找到控件并调用存储过程。



看看会发生什么并尝试调试......
Your question is very hard to figure but I am trying to guess your problem here.

You need to call the stored procedure inside a loop.
1. In the submit button click, find the number of tables
2. Loop through them.
3. Inside the loop, find controls and call the stored procedure.

See what happens and try to debug...


这篇关于如何摆脱将两个面板控制数据保存到数据库时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆