I am creating a page to search for a user in a database and display the results in a gata grid (Which i have done) Then i would like to select one of the results and use this record by holding it as a variable and pass it back into the database (which i cant do!) Help!
this is the aspx.VB code
Imports System.Data.OleDb
Imports System.Data
Partial Class Search3
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button2_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim objCommand As OleDbCommand
Dim objAdapter As OleDbDataAdapter
Dim objDataSet As DataSet
Dim strSearch As String
Dim objConnection As String = ("Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & Server.MapPath("DB\ScrumManagementSystem.accdb") & ";")
Dim cn As New OleDbConnection(objConnection)
Dim strSQLQuery As String
strSearch = TextBox1.Text
If Len(Trim(strSearch)) > 0 Then
strSQLQuery = "SELECT FName & SName & ProductOwnerRole FROM tblUser WHERE ProductOwnerRole <> 'false' AND FName LIKE '%" & Replace(strSearch, "'", "''") & "%' ORDER BY FName;"
cn.Open()
Dim cmd As New OleDbCommand(strSQLQuery, cn)
objCommand = New OleDbCommand(strSQLQuery, cn)
objAdapter = New OleDbDataAdapter(objCommand)
objDataSet = New DataSet()
objAdapter.Fill(objDataSet)
dgPaging1.DataSource = objDataSet
dgPaging1.DataBind()
cn.Close()
Else
TextBox1.Text = "Enter search criteria!"
End If
End Sub
Protected Sub Button3_OnClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim objCommand As OleDbCommand
Dim objAdapter As OleDbDataAdapter
Dim objDataSet As DataSet
Dim strSearch As String
Dim objConnection As String = ("Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & Server.MapPath("DB\ScrumManagementSystem.accdb") & ";")
Dim cn As New OleDbConnection(objConnection)
Dim strSQLQuery As String
strSearch = TextBox2.Text
If Len(Trim(strSearch)) > 0 Then
strSQLQuery = "SELECT ProjectName & Description FROM tblProject WHERE ProjectName LIKE '%" & Replace(strSearch, "'", "''") & "%' ORDER BY ProjectName;"
cn.Open()
Dim cmd As New OleDbCommand(strSQLQuery, cn)
objCommand = New OleDbCommand(strSQLQuery, cn)
objAdapter = New OleDbDataAdapter(objCommand)
objDataSet = New DataSet()
objAdapter.Fill(objDataSet)
dgPaging2.DataSource = objDataSet
dgPaging2.DataBind()
cn.Close()
Else
TextBox2.Text = "Enter search criteria!"
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
'Declaration of variables
Dim myConnection2 As OleDbConnection
Dim myCommand2 As OleDbCommand
Dim sql As String
Dim dlstDataListItem As DataListItem
Dim intItemIndex As Int32
'SQL query to access the table tblProject
sql = "insert into tblProject "
sql = sql & "(ProjectName)"
sql = sql & "values('" "')"
'Creates a connection to the database
myConnection2 = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & Server.MapPath("DB\ScrumManagementSystem.accdb") & ";")
'Opens a connection
myConnection2.Open()
myCommand2 = New OleDbCommand(sql, myConnection2)
myCommand2.ExecuteNonQuery()
'Closes the connection
myConnection2.Close()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Declaration of variables
Dim myConnection As OleDbConnection
Dim myCommand As OleDbCommand
Dim sql1 As String
'SQL query to access the table tblProject
sql1 = "insert into tblProject "
sql1 = sql1 & "(FName)"
sql1 = sql1 & "values(LinkButton2)"
'Creates a connection to the database
myConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" _
& "Data Source=" & Server.MapPath("DB\ScrumManagementSystem.accdb") & ";")
'Opens a connection
myConnection.Open()
myCommand = New OleDbCommand(sql1, myConnection)
myCommand.ExecuteNonQuery()
'Closes the connection
myConnection.Close()
Response.Redirect("ProductBacklog.aspx")
End Sub
End Class
this is the aspx code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Search3.aspx.vb" Inherits="Search3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Untitled Page</title>
<style type="text/css">
#Select1
{
height: 54px;
width: 138px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="site">
<div id="header">
<img src = "images/header.gif" alt=".NETMARE LOGO" /> <div id="menu"><!--#include file="menutest.html"--></div>
<h1>Adding product owners to projects</h1>
</div>
<div class="box-content">
<asp:Label ID="Label1" runat="server" Text="Enter a registered product owner"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Height="22px"
style="font-weight: 700" Text="Search" Width="57px" />
<br />
<br />
<asp:Label ID="Label3" runat="server" Text="Results:"></asp:Label>
<br />
<br />
<asp:GridView ID="dgPaging1" runat="server">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Select" Text="Select B">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Enter a project to add them to:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button3" runat="server" Height="20px"
style="font-weight: 700" Text="Search" Width="62px" />
<br />
<br />
<asp:Label ID="Label4" runat="server"
Text="Results:"></asp:Label>
<br />
<asp:GridView ID="dgPaging2" runat="server">
<Columns>
<asp:TemplateField ShowHeader="false">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Select" Text="Select">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br>
<br>
<asp:Button ID="Button1" runat="server" style="font-weight: 700"
Text="Update" />
<br>
<br>
<br>
<div id="footer"><!--#include file="footer.html"--></div>
</div>
</div>
</form>
</body>
</html>