我需要帮助生成代码 [英] i need help generating a code

查看:74
本文介绍了我需要帮助生成代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 batten 按钮,通过读取文本框Id编号在Db中搜索表格,然后在网格中显示结果,这是代码:

< br $> b $ b

 受保护的  Sub  btnSearch_Click( ByVal  sender 作为 对象 ByVal  e  As  System.EventArgs) Handles  btnSearch.Click 
Dim con As OleDbConnection( Provider = Microsoft.Jet.OLEDB.4.0; data source = & Server.MapPath( 〜/ Members.mdb))
暗淡 cmd 作为 OleDbCommand
Dim rd As OleDbDataReader
lblerror.Text =
cmd.Connection = con
cmd.CommandType = Data.CommandType.Text
cmd.CommandText = 从KMM_STU中选择*,其中KMM_STU_ID类似于@KMM_STU_ID
cmd.Parameters.Add( KMM_STU_ID,OleDbType.VarChar).Value = & txtSTU_ID.Text&
con.Open()
rd = cmd.ExecuteReader

如果 rd.HasRows()那么
GridView1.DataSource = rd
GridView1.DataBind()
rd.Close()
con.Close()
Else
lblerror.text = 未找到任何记录
结束 如果







现在我添加了另一个 batten 按钮来保存已生成到新表中的同一记录中的信息,其中ID =文本框中的id但是我不知道怎么办?





为了清晰而修复的错误仅为按钮的batten - OriginalGriff [/编辑] <二v class =h2_lin>解决方案

为新记录运行插入查询并将其插入新表格,



http://www.w3schools.com/sql/sql_insert.asp [ ^ ]


1。使数据源与您正在使用的数据库连接,然后选择该表,

2.对于数据绑定网格视图,您可以使用以下内容:



 Datasource1.Selectcommand =  从KMM_STU中选择*其中KMM_STU_ID类似于 & txtSTU_ID.Text&  
Datasource1.Databind()
Gridview1.databind()


I have a batten button to search in a table from Db by reading from text box Id number then displaying the result in a grid this is the code:


Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
       Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source= " & Server.MapPath("~/Members.mdb"))
       Dim cmd As New OleDbCommand
       Dim rd As OleDbDataReader
       lblerror.Text = ""
       cmd.Connection = con
       cmd.CommandType = Data.CommandType.Text
       cmd.CommandText = "select * from KMM_STU where KMM_STU_ID like @KMM_STU_ID"
       cmd.Parameters.Add("KMM_STU_ID", OleDbType.VarChar).Value = "%" & txtSTU_ID.Text & "%"
       con.Open()
       rd = cmd.ExecuteReader

       If rd.HasRows() Then
           GridView1.DataSource = rd
           GridView1.DataBind()
           rd.Close()
           con.Close()
       Else
           lblerror.text = "No Records were Found"
       End If




and now I added another batten button to save the information from the same record that have been generated into a new table where the ID = the id in the text box but i don''t know how?


[edit]Typo fixed for clarity only "batten" for "button" - OriginalGriff[/edit]

解决方案

Run an insert query for the new record and insert it into your new table,

http://www.w3schools.com/sql/sql_insert.asp[^]


1. Make a datasource connected with database that you are using , then select that table,
2.For data bind grid-view you can use the following :

Datasource1.Selectcommand="select * from KMM_STU where KMM_STU_ID like "%" & txtSTU_ID.Text & "%"
Datasource1.Databind()
Gridview1.databind()


这篇关于我需要帮助生成代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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