M
mentor714
I just started learning ASP.NET (newb) and would like to use it to
connect to an ACCESS Db. Im using WebMatrix to start out. I created a
TextBox and Button so a user can query the Db.
Sub btnSearch_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=E:\PCMS.mdb"
Dim CommandText As String
CommandText = "SELECT [Module].* FROM
[Module] WHERE [Module].ModuleName= " +
"'TextBox1.Text'"
Dim myConnection As New
OleDbConnection(ConnectionString)
Dim myCommand As New OleDbDataAdapter(CommandText,
myConnection)
Dim ds As New DataSet()
myCommand.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
My question is: Why wont a simple concat from the Textbox work when
completing the SQL statement?
Also I created a seperate page for adding records to the database.
All the information will be read from textboxes. Am I on the correct
track?
[code:1:a653d68270]
Sub btnSubmit_Click(sender As Object, e As EventArgs)
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=E:\PCMS.mdb"
Dim dbConnection As New OleDbConnection(connectionString)
dbConnection.Open()
Dim commandString As String = "INSERT INTO Module
(ModuleName, ModuleType, PartOf, Purpose, Designer, Date,
ModuleBody) " & _
"Values(@ModName, @ModType, @PartOf, @Purpose, @Designer,
@Date, @ModBody)"
Dim dbCommand As New OleDbCommand(commandString,
dbConnection)
Dim ModNameParam As New OleDbParameter("@ModName",
OleDbType.VarChar, 50)
ModNameParam.Value = txtModuleName.Text
dbCommand.Parameters.Add(ModNameParam)
Dim ModTypeParam As New OleDbParameter("@ModType",
OleDbType.VarChar, 50)
ModTypeParam.Value = txtModuleType.Text
dbCommand.Parameters.Add(ModTypeParam)
' the rest of the variables omitted in order to save space for post
Dim ModBodyParam As New OleDbParameter("@ModBody",
OleDbType.VarChar, 100)
ModBodyParam.Value = txtModuleBody.Text
dbCommand.Parameters.Add(ModBodyParam)
dbCommand.ExecuteNonQuery()
dbConnection.Close()
End Sub
[/code:1:a653d68270]
Thank you very much in advance...because I cant get my code to work
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
connect to an ACCESS Db. Im using WebMatrix to start out. I created a
TextBox and Button so a user can query the Db.
Sub btnSearch_Click(sender As Object, e As EventArgs)
Dim ConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=E:\PCMS.mdb"
Dim CommandText As String
CommandText = "SELECT [Module].* FROM
[Module] WHERE [Module].ModuleName= " +
"'TextBox1.Text'"
Dim myConnection As New
OleDbConnection(ConnectionString)
Dim myCommand As New OleDbDataAdapter(CommandText,
myConnection)
Dim ds As New DataSet()
myCommand.Fill(ds)
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
My question is: Why wont a simple concat from the Textbox work when
completing the SQL statement?
Also I created a seperate page for adding records to the database.
All the information will be read from textboxes. Am I on the correct
track?
[code:1:a653d68270]
Sub btnSubmit_Click(sender As Object, e As EventArgs)
Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=E:\PCMS.mdb"
Dim dbConnection As New OleDbConnection(connectionString)
dbConnection.Open()
Dim commandString As String = "INSERT INTO Module
(ModuleName, ModuleType, PartOf, Purpose, Designer, Date,
ModuleBody) " & _
"Values(@ModName, @ModType, @PartOf, @Purpose, @Designer,
@Date, @ModBody)"
Dim dbCommand As New OleDbCommand(commandString,
dbConnection)
Dim ModNameParam As New OleDbParameter("@ModName",
OleDbType.VarChar, 50)
ModNameParam.Value = txtModuleName.Text
dbCommand.Parameters.Add(ModNameParam)
Dim ModTypeParam As New OleDbParameter("@ModType",
OleDbType.VarChar, 50)
ModTypeParam.Value = txtModuleType.Text
dbCommand.Parameters.Add(ModTypeParam)
' the rest of the variables omitted in order to save space for post
Dim ModBodyParam As New OleDbParameter("@ModBody",
OleDbType.VarChar, 100)
ModBodyParam.Value = txtModuleBody.Text
dbCommand.Parameters.Add(ModBodyParam)
dbCommand.ExecuteNonQuery()
dbConnection.Close()
End Sub
[/code:1:a653d68270]
Thank you very much in advance...because I cant get my code to work
*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*