|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
can i do this with real database, not just datasetIn the new vb.net is a thing called dataset, which I guess is a standalone database you can create and play with. The following code works fine for that. But I can't seem to define things so that it would work against a real database. Here's code that creates an access database, with no structure or fields on the disk: If CreateAccessDatabase("e:\test2.mdb") = True Then MsgBox("Database Created") Else MsgBox("Database Creation Failed") End If Public Function CreateAccessDatabase( _ ByVal DatabaseFullPath As String) As Boolean Dim bAns As Boolean Dim cat As New ADOX.Catalog() Try 'Make sure the folder 'provided in the path exists. If file name w/o path 'is specified, the database will be created in your 'application folder. Dim sCreateString As String sCreateString = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ DatabaseFullPath cat.Create(sCreateString) bAns = True Catch Excep As System.Runtime.InteropServices.COMException bAns = False 'do whatever else you need to do here, log, 'msgbox etc. Finally cat = Nothing End Try Return bAns End Function I want to use code like the code below to add the fields to the database. Is there a way to do this? Thanks. Scott Public Sub createdataset() 'Dim ds As New DataSet() ' Create a table; set its initial capacity. Dim dtEmp As New DataTable("Employees") dtEmp.MinimumCapacity = 200 ' Create all columns. ' You can create a DataColumn and then add it to the Columns collection. Dim dcFName As New DataColumn("FirstName", GetType(String)) dtEmp.Columns.Add(dcFName) ' Or you can create an implicit DataColumn with the Columns.Add method. dtEmp.Columns.Add("LastName", GetType(String)) dtEmp.Columns.Add("BirthDate", GetType(Date)) ' When you have to set additional properties, you can use an explicit ' DataColumn object, or you can use a With block. With dtEmp.Columns.Add("HomeAddress", GetType(String)) .MaxLength = 100 End With ' (When you must set only one property, you can be more concise, ' even though the result isn't very readable.) dtEmp.Columns.Add("City", GetType(String)).MaxLength = 20 ' Create a calculated column by setting the Expression ' property or passing it as the third argument to the Add method. dtEmp.Columns.Add("CompleteName", GetType(String), _ "FirstName + ' ' + LastName") ' Create an identity, auto-incremented column. Dim dcEmpId As New DataColumn("EmpId", GetType(Integer)) dcEmpId.AutoIncrement = True ' Make it auto-increment. dcEmpId.AutoIncrementSeed = 1 dcEmpId.AllowDBNull = False ' Default is True. dcEmpId.Unique = True ' All key columns should be unique. dtEmp.Columns.Add(dcEmpId) ' Add to Columns collection. ' Make it the primary key. (Create the array on-the-fly.) dtEmp.PrimaryKey = New DataColumn() {dcEmpId} ' This is a foreign key, but we haven't created the other table yet. dtEmp.Columns.Add("DeptId", GetType(Integer)) ' Add the DataTable to the DataSet. ds.Tables.Add(dtEmp) End Subl "Scott Baxter" <sc***@websearchstore.com> wrote in message (You got one group right, and the other wrong.)news:uNrZEZ47JHA.1432@TK2MSFTNGP02.phx.gbl... > In the new vb.net [Canned response] This is a VB "classic" newsgroup. Questions about VB.NET (including VB 2005/2008 and VB Express, which have dropped .NET from their names) are off-topic here. Please ask .NET questions in newsgroups with "dotnet" in their names. The *.vb.* groups are for VB6 and earlier. If you don't see the *.dotnet.* groups on your news server, connect directly to the Microsoft server: msnews.microsoft.com. For questions specific to the VB.NET language, use this group: microsoft.public.dotnet.languages.vb Please note that things like controls and data access, which have their own subgroups in the Classic VB hierarchy, are not language-specific in .NET, so you should look for groups like these: microsoft.public.dotnet.framework.windowsforms.controls microsoft.public.dotnet.framework.adonet (Note that "vb" is not present in the group name.) Hi Jeff,
"Jeff Johnson" <i.get@enough.spam> wrote in message Huh ? So you now claiming that :news:ealIDz47JHA.1424@TK2MSFTNGP02.phx.gbl... > The *.vb.* groups are for VB6 and earlier. microsoft.public.dotnet.languages.vb.data is for VB6 and earlier only ? "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message Great. Thanks, MS, for breaking what little consistency you had in newsgroup news:%23qNBNtH8JHA.1336@TK2MSFTNGP05.phx.gbl... >> The *.vb.* groups are for VB6 and earlier. > > Huh ? So you now claiming that : > > microsoft.public.dotnet.languages.vb.data > > is for VB6 and earlier only ? naming. Clearly Visual Basic developers are WAAAAAAY too stupid to be able to figure out how to go to other groups for specific questions, so you had to make groups just for their tiny little minds, eh? Typical of the way we've always been treated.... But you know what, Bill? I'm not changing my blurb. There are all of 4 *.vb.* groups for VB.NET, and a huge number for Classic VB. Hopefully VB programmers are smarter than MS thinks they are and can clearly see the "dotnet" in the .NET group names. (Not only that, but I mention the "dotnet" thing in my blurb. I now consider it "an exercise for the reader.") Jeff,
You were so fine handling this kind of things lately. People are forced to this newsgroup because all what is written in this newsgroup about .Net, I discovered that very late, I thought the webmaster at Microsoft newsgroup server had done this. I've answered this question by the way in the dotNet.languages.vb newsgroup. (A little bit late however) Cor Show quoteHide quote "Jeff Johnson" <i.get@enough.spam> wrote in message news:%23Y8UkWP8JHA.2120@TK2MSFTNGP02.phx.gbl... > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message > news:%23qNBNtH8JHA.1336@TK2MSFTNGP05.phx.gbl... > >>> The *.vb.* groups are for VB6 and earlier. >> >> Huh ? So you now claiming that : >> >> microsoft.public.dotnet.languages.vb.data >> >> is for VB6 and earlier only ? > > Great. Thanks, MS, for breaking what little consistency you had in > newsgroup naming. Clearly Visual Basic developers are WAAAAAAY too stupid > to be able to figure out how to go to other groups for specific questions, > so you had to make groups just for their tiny little minds, eh? Typical of > the way we've always been treated.... > > But you know what, Bill? I'm not changing my blurb. There are all of 4 > *.vb.* groups for VB.NET, and a huge number for Classic VB. Hopefully VB > programmers are smarter than MS thinks they are and can clearly see the > "dotnet" in the .NET group names. (Not only that, but I mention the > "dotnet" thing in my blurb. I now consider it "an exercise for the > reader.") > "Jeff Johnson" <i.get@enough.spam> wrote in message <usual blame Microsoft dribble snipped />news:%23Y8UkWP8JHA.2120@TK2MSFTNGP02.phx.gbl... > "Bill McCarthy" <TPASoft.com Are Identity Thieves> wrote in message > news:%23qNBNtH8JHA.1336@TK2MSFTNGP05.phx.gbl... > >>> The *.vb.* groups are for VB6 and earlier. >> >> Huh ? So you now claiming that : >> >> microsoft.public.dotnet.languages.vb.data >> >> is for VB6 and earlier only ? > > Uh huh. Do you really think that kind of attitude is useful ?> But you know what, Bill? I'm not changing my blurb. > There are all of 4 *.vb.* groups for VB.NET, Well depends on how you define *.vb.* really. In file systems, the trailing ..* would include groups such as microosft.public.dotnet.languages.vb as well. In google groups it is definetly goign to bring in all the different vb dotnet newsgroups. so where exactly do you think this wild card filter of your's actually applies and doesn't include the dotnet newsgroups. > and a huge number for Classic VB. Yep many of which have zero usage and should be closed, but that's another topic ;) > Hopefully VB programmers are smarter than MS thinks they are and can Uhm, well if you think that, doesn't that make your entire ost redundant ??> clearly see the "dotnet" in the .NET group names. > Not only that, but I mention the "dotnet" thing in my blurb. Yes, but you then go on to contradict that and confuse the matter with the *.vb.* claim. Hi Scott,
Dataset is similar to a collection of recordsets, in that it is an in memory only model. As to creating tables and columns in the actual database, I'm not sure on an access db, but I would have thought you'd script that, eg CREATE TABLE etc. Also please note for .NET related newsgroups via NTTP, look for dotnet in the newsgroup name, eg: microsoft.public.dotnet.languages.vb For the web based forums : http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/threads note that on the web based forums the "Visual Basic General" discussion group is for VB7 (2002) and later questions, so you are welcome to post VB .NET questions to there. Unfortunately the web based and nntp based newsgroup names are the same, yet the web is for VB7 and later, whereas on nttp there are other .NET specific newsgroups. Show quoteHide quote "Scott Baxter" <sc***@websearchstore.com> wrote in message news:uNrZEZ47JHA.1432@TK2MSFTNGP02.phx.gbl... > Hello, > > In the new vb.net is a thing called dataset, which I guess is a standalone > database you can create and play with. > > The following code works fine for that. > > But I can't seem to define things so that it would work against a real > database. > > Here's code that creates an access database, with no structure or fields > on the disk: > > > If CreateAccessDatabase("e:\test2.mdb") = True Then > MsgBox("Database Created") > Else > MsgBox("Database Creation Failed") > End If > > Public Function CreateAccessDatabase( _ > ByVal DatabaseFullPath As String) As Boolean > Dim bAns As Boolean > Dim cat As New ADOX.Catalog() > Try > > > 'Make sure the folder > 'provided in the path exists. If file name w/o path > 'is specified, the database will be created in your > 'application folder. > > Dim sCreateString As String > sCreateString = _ > "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ > DatabaseFullPath > cat.Create(sCreateString) > > bAns = True > > Catch Excep As System.Runtime.InteropServices.COMException > bAns = False > 'do whatever else you need to do here, log, > 'msgbox etc. > Finally > cat = Nothing > End Try > Return bAns > End Function > > > I want to use code like the code below to add the fields to the database. > > Is there a way to do this? > > Thanks. > > Scott > > > > > Public Sub createdataset() > 'Dim ds As New DataSet() > ' Create a table; set its initial capacity. > Dim dtEmp As New DataTable("Employees") > dtEmp.MinimumCapacity = 200 > ' Create all columns. > ' You can create a DataColumn and then add it to the Columns > collection. > Dim dcFName As New DataColumn("FirstName", GetType(String)) > dtEmp.Columns.Add(dcFName) > ' Or you can create an implicit DataColumn with the Columns.Add > method. > dtEmp.Columns.Add("LastName", GetType(String)) > dtEmp.Columns.Add("BirthDate", GetType(Date)) > ' When you have to set additional properties, you can use an > explicit > ' DataColumn object, or you can use a With block. > With dtEmp.Columns.Add("HomeAddress", GetType(String)) > .MaxLength = 100 > End With > ' (When you must set only one property, you can be more concise, > ' even though the result isn't very readable.) > dtEmp.Columns.Add("City", GetType(String)).MaxLength = 20 > ' Create a calculated column by setting the Expression > ' property or passing it as the third argument to the Add method. > dtEmp.Columns.Add("CompleteName", GetType(String), _ > "FirstName + ' ' + LastName") > ' Create an identity, auto-incremented column. > Dim dcEmpId As New DataColumn("EmpId", GetType(Integer)) > dcEmpId.AutoIncrement = True ' Make it auto-increment. > dcEmpId.AutoIncrementSeed = 1 > dcEmpId.AllowDBNull = False ' Default is True. > dcEmpId.Unique = True ' All key columns should be unique. > dtEmp.Columns.Add(dcEmpId) ' Add to Columns collection. > ' Make it the primary key. (Create the array on-the-fly.) > dtEmp.PrimaryKey = New DataColumn() {dcEmpId} > ' This is a foreign key, but we haven't created the other table > yet. > dtEmp.Columns.Add("DeptId", GetType(Integer)) > ' Add the DataTable to the DataSet. > ds.Tables.Add(dtEmp) > End Subl
Inno Setup and Dependencies
Download multiple files concurrently using WinHttpRequest When the compiler freezes.... what is the rescue? How to Change $(AppPath) in PDWizard? The JET VBA File...Help Please! File not found How to obtain the new GUIID key on a new build of an ActiveX DLL or an ActiveX OCX Autosize DataGrid Columns Using Outlook object How to create a VB6 app that opens a file when the file is double |
|||||||||||||||||||||||