同时插入时间记录的记录将在gridview中显示 [英] while inserting the record that time simtaneously record to be shown in the gridview

查看:57
本文介绍了同时插入时间记录的记录将在gridview中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计屏幕如下



证书否textbox1.text

Studentid textbox2.text

Coursename dropdownlist1

开始日期dropdownlist2 dropdownlist3 dropdownlist4

(日期)(月)(年)



结束日期dropdownlist5 dropdownlist6 dropownlist7

(日期)(月)(年)



插入按钮代码如下

Design screen as follows

Certificate No textbox1.text
Studentid textbox2.text
Coursename dropdownlist1
start date dropdownlist2 dropdownlist3 dropdownlist4
(Date) (Month) (Year)

End date dropdownlist5 dropdownlist6 dropownlist7
(Date) (Month) (Year)

Insert Button code as follows

String  startdate;
       DateTime Batchstartdate;
       startdate = this.dropdownlist2.Text.ToString().Trim() + "-" + this.dropdownlist3.Text.ToString().Trim() + "-" + this.dropdownlist4.Text.ToString().Trim();
       Batchstartdate = Convert.ToDateTime(startdate.ToString());

       string issuedate;
       DateTime Batchissuedate;
       issuedate = this.dropdownlist5.Text.ToString().Trim() + "-" + this.dropdownlist6.Text.ToString().Trim() + "-" + this.dropdownlist7.Text.ToString().Trim();
       Batchissuedate = Convert.ToDateTime(issuedate.ToString());



       //Validating for student already course is there
       try
       {
           sql = "select stud_id,Cmn_Minor_code  from Tb_Past_Certificate_details where Stud_ID = '" + textbox2.text + "' and Cmn_Minor_code = '" + dropdownlist1.Text + "' and PCD_Active <> 'D'";
           drcoursea = drr.ExecRdr(sql);
           if (drcoursea.HasRows == true)
           {
               Label23.Text = "Already seleceted course is entered";
           }

           else
           {
               sql = "insert into Tb_Past_Certificate_details values('" + textbox1.Text.ToString().Trim() + "','" + textbox2.text.ToString().Trim() + "','" + dropdownlist1.Text.ToString() + "','" + startdate.ToString() + "','" + issuedate.ToString() + "','Online','" + DateTime.Now.ToString() + "','F')";
               drr.InserData(sql);

 sql = "select * from Tb_Past_Certificate_details values where stud_id = '" + textbox2.text.ToString().Trim() + "' and coursename = '" + drpdownlist.text.tostring() + "'";
       dr = drr.ExecRdr(sql);
       GridView3.DataSource = dr;
       GridView3.DataBind();

           }
       }
       catch (Exception ex)
       {
           Label23.Text = ex.ToString();
           return;
       }



插入记录时我的上述代码是否正确,时间显示在gridview中的特定学生记录。

请帮帮我。



Rgds,

Narasiman P.


whether my above code is correct while inserting the record that time shows the particular student record in the gridview.
please help me.

Rgds,
Narasiman P.

推荐答案



如果你想在保存之后获得最后一次插入的记录返回,那么select查询将如此简单,就像我的代码一样,
Hi,
if you want to get the last inserted record return after it saved then the select query will be so simple like I moodified your code
String  startdate;
        DateTime Batchstartdate;
        startdate = this.dropdownlist2.Text.ToString().Trim() + "-" + this.dropdownlist3.Text.ToString().Trim() + "-" + this.dropdownlist4.Text.ToString().Trim();
        Batchstartdate = Convert.ToDateTime(startdate.ToString());
 
        string issuedate;
        DateTime Batchissuedate;
        issuedate = this.dropdownlist5.Text.ToString().Trim() + "-" + this.dropdownlist6.Text.ToString().Trim() + "-" + this.dropdownlist7.Text.ToString().Trim();
        Batchissuedate = Convert.ToDateTime(issuedate.ToString());
 

 
        //Validating for student already course is there
        try
        {
            sql = "select stud_id,Cmn_Minor_code  from Tb_Past_Certificate_details where Stud_ID = '" + textbox2.text + "' and Cmn_Minor_code = '" + dropdownlist1.Text + "' and PCD_Active <> 'D'";
            drcoursea = drr.ExecRdr(sql);
            if (drcoursea.HasRows == true)
            {
                Label23.Text = "Already seleceted course is entered";
            }
 
            else
            {
                sql = "insert into Tb_Past_Certificate_details values('" + textbox1.Text.ToString().Trim() + "','" + textbox2.text.ToString().Trim() + "','" + dropdownlist1.Text.ToString() + "','" + startdate.ToString() + "','" + issuedate.ToString() + "','Online','" + DateTime.Now.ToString() + "','F')";
                drr.InserData(sql);
 
  sql = "select top 1 * from Tb_Past_Certificate_details order by ID desc";
        dr = drr.ExecRdr(sql);
        GridView3.DataSource = dr;
        GridView3.DataBind();
  
            }
        }
        catch (Exception ex)
        {
            Label23.Text = ex.ToString();
            return;
        }

在select查询中请确保ID是表的主键,你应该使用你的表的PK。

祝你好运: )

here in the select query please make sure that the ID is the primary key of the table, you should use your table's PK.
best of luck :)


sql = "select top 1 * from Tb_Past_Certificate_details order by 1 desc";
        dr = drr.ExecRdr(sql);
        GridView3.DataSource = dr;
        GridView3.DataBind();





这里1是它代表的列索引第一列



使用主键列索引



Here 1 is the column index it represent First column

use primary key column index


这篇关于同时插入时间记录的记录将在gridview中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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