Jump to content
Xtreme .Net Talk

Robby

Moderators
  • Posts

    3848
  • Joined

  • Last visited

Everything posted by Robby

  1. The NZ was to check if the field is null so you don't get an error, once you get this working and understand it, I'll spring that on you. (not that it's very complicated)
  2. try this... Private Function GetTableValue(ByVal strVal As String, ByVal sField As String, ByVal sTable As String) As string Dim drSqlReader As SqlDataReader Dim SqlCMD As SqlCommand Dim SqlCN As New SqlConnection(Conn) Dim strSql As String, sTemp As string ="" Try If SqlCN.State = ConnectionState.Closed Then SqlCN.Open() strSql = "SELECT " & sField & " FROM " & sTable & " WHERE User = '" & strVal & "'" SqlCMD = New SqlCommand(strSql, SqlCN) drSqlReader = SqlCMD.ExecuteReader() While drSqlReader.Read sTemp = drSqlReader.Item(sField) End While Catch sTemp = "error found" Finally If Not SqlCN.State = ConnectionState.Closed Then SqlCN.Close() If Not drSqlReader.IsClosed Then drSqlReader.Close() If Not SqlCMD Is Nothing Then SqlCMD.Dispose() End Try Return sTemp End Function 'and call it like this... dim sResults as string = GetTableValue("somename","User", "tmTransactions") messagebox.show(sResults)
  3. Sorry about the NZ(), it's my own function.
  4. You can change some of the variables to hard-coded if you wish... Private Function GetTableValue(ByVal nID As Integer, ByVal sField As String, ByVal sTable As String) As Integer Dim drSqlReader As SqlDataReader Dim SqlCMD As SqlCommand Dim SqlCN As New SqlConnection(Conn) Dim strSql As String, intTemp As Integer Try If SqlCN.State = ConnectionState.Closed Then SqlCN.Open() strSql = "SELECT " & sField & " FROM " & sTable & " WHERE ID = " & nID SqlCMD = New SqlCommand(strSql, SqlCN) drSqlReader = SqlCMD.ExecuteReader() While drSqlReader.Read intTemp = CType(Nz(drSqlReader.Item(sField), ""), Integer) End While Catch intTemp = -1 Finally If Not SqlCN.State = ConnectionState.Closed Then SqlCN.Close() If Not drSqlReader.IsClosed Then drSqlReader.Close() If Not SqlCMD Is Nothing Then SqlCMD.Dispose() End Try Return intTemp End Function
  5. Correct me if I'm wrong, do you want to use paging feature of a datagrid but without a datagrid? How are you displaying the data?
  6. It shouldn't matter if it's a Select or Insert, the single quotes surrounding the string will work. I hope that the fields' data type is a string.
  7. I wouldn't bother with something like this, but if you really want.... you can put together a calculation to manage DataSet1.Tables(0).Rows.Count * n would be the datagrid height. Be careful not to exeed the forms' height.
  8. "select * from myTable where field = '" & textbox.text.tostring & "'"
  9. Recordset? Do you mean Dataset?
  10. ADO.NET does not use COM/ActiveX it's a class library. Anytime you Import(s) System.Data.OleDb or SqlClient you are using ADO.NET. In order to use an ActiveX component you must Add Reference into the project. Which hopefully you have not done. :) The connection string in both ADOs can be the same, the string indicates which version of JET to use. (in the case of Accesss). The Create Table statement uses the OleDbCommand, which is ADO.NET, however you can use the exact same statement in VB6 using ADO COM. Now to create a database.... I can do it using SqlClient but not OleDB, I'm sure it's possible though, and maybe someone will eventually point it out. But for now the only way I know is to use ADOX (COM) which is spelled out in Thinkers' example (in the link) Sorry I couldn't be more help.
  11. The code above does not populate a Datagrid, it creates tables from scratch. I don't know how to create a database using ADO.NET, that's why I provided the Com solution for now. Why not use COM/ActiveX/DLL? ... DOT NET was designed to do away with it all and only use managed code. I'm sure someone else will elaborate.
  12. First you need to declare the objects with WithEvents, and I don't think you can add ColumnChanging handler to a Dataset.. Maybe you ment to handle the Datagrid events?
  13. I recommend downloading 101 Samples from MS... http://msdn.microsoft.com/vbasic/downloads/samples/default.asp Most of the samples use SQL Server, but it will get you started.
  14. You can use HttpServerUtility.Transfer, it is dicussed in VS.NET help section, look up "Passing Server Control Values Between Pages". They cover In-line as well as Code-behind.
  15. What type of data is it, and where is it coming from? (Page values or files from the client, etc..)
  16. I don't know how to create an Access database, only SQL Server. You can use ADOX as Thinker demos in this sample...http://www.visualbasicforum.com/showthread.php?s=&threadid=20002 Once you get the database created, here's how to create a table using vb.net... Try Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\test.mdb") con.Open() Dim cmd As New OleDbCommand("CREATE TABLE " & TextBox1.Text.ToString & " (Col1 Text, col2 Text)", con) cmd.ExecuteNonQuery() con.Close() Catch ex As Exception MessageBox.Show(ex.ToString) End Try
  17. You mean that the old one works on that machine? That's weird! Which OS is it?
  18. Actually what I would do is create a new project with nothing it, maybe a simple Hello World. See if it runs.
  19. How about MDAC?
  20. And have you installed all these in the machine?
  21. Well? What are you using then?
  22. Is there any ActiveX, Com or Database usage?
  23. Dim cmd As New SqlCommand("CREATE TABLE " & TextBox1.Text.ToString & " (Col1 Text, col2 Text)", con)
  24. try this... Dim con As New SqlConnection("server=127.0.0.1;Trusted_Connection=yes;database=Northwind") con.Open() Dim cmd As New SqlCommand("CREATE TABLE Test (Col1 Text, col2 Text)", con) cmd.ExecuteNonQuery() con.Close()
  25. The easiest way is... Create a new project, then in Admin Tools >> Internet Services Manager >> click on Defult Web Site >> right-click your project name >> Properties >> Click on "Create". That's it
×
×
  • Create New...