Showing posts with label app. Show all posts
Showing posts with label app. Show all posts

Monday, March 26, 2012

Noob to VWD 2005 - Insert from textbox into SQL DB

I have followed all the tutorials and I think I have a pretty good grasp on how to get info from the SQL database running on my machine in the App Data directory. My question is simple and probably the answer is nested in the 148 pages of this very informative forum.

How do I take the 15 textbox fields worth of data and insert them into the SQL db? I am pretty familiar with general sql concepts (mysql, mssql, postgresql), but I have only been in this IDE for about a week now and I need to get my project up and running quickly. I am just unfamiliar with VB in general, but I do understand the object.method concept.

I gathered that I need to make the insert statement part of the button click "event". I cannot find any good "starter" documentation on getting this process to work. I understand the grid and form and detail view really well and have tested my 2nd app with success, but it requires the db to be populated by a web front end. I have read a few MSDN links but they are not helping much, they just keep linking me back to grid and detal and form views.


Help? Please? Pretty Please?


- Chris

roninuta:

I have followed all the tutorials and I think I have a pretty good grasp on how to get info from the SQL database running on my machine in the App Data directory. My question is simple and probably the answer is nested in the 148 pages of this very informative forum.

How do I take the 15 textbox fields worth of data and insert them into the SQL db? I am pretty familiar with general sql concepts (mysql, mssql, postgresql), but I have only been in this IDE for about a week now and I need to get my project up and running quickly. I am just unfamiliar with VB in general, but I do understand the object.method concept.

I gathered that I need to make the insert statement part of the button click "event". I cannot find any good "starter" documentation on getting this process to work. I understand the grid and form and detail view really well and have tested my 2nd app with success, but it requires the db to be populated by a web front end. I have read a few MSDN links but they are not helping much, they just keep linking me back to grid and detal and form views.


Help? Please? Pretty Please?


- Chris

This link...

http://www.WebLogicArts.com/DemoSqlServerDatabase01.aspx

...is a working sample with source code that shows one simple way to CreateOne/ UpdateOne/ DeleteOne/ RetrieveOne/ RetrieveAll using ASP.NET and SQL Sever 2000.

HTH.

Thank you.

-- Mark Kamoski

|||

Ok, there are two very simple ways you can do this.

1) Using the SQLDataSource object and after creating the connection using the GUI. You can find the SqlDataSource control in the toolbox. Although easy to use I don't like it too much, prefer writing SLQ statements on my own allows for more flexibility. However, to use the SqlDataSource object you are forced to create an SQL statement using the GUI, but this can be countermanded. So what I do is use the SQLDataSource object's SelectCommand and use its SelectCommand method to write my own SQL statement. Basically SQLDataSource1.SelectCommand = "Select * from whatever". To include textboxes, like in a search your SQL statement should look like this

"Select * from Table WHERE Table.Column = '" & textbox1.text & "'"

You can extrapolate to Insert and Update.

2) Another way of using SQL in VWD2005E is to call ADODB objects. I find this the best method to do inserts and such. First you have to make a reference to the DLL, to do this you go to Website->Add Reference click on the COM tab and find Microsoft ActiveX Data Objects, pick one and click OK. To use ADODB you first declare it then set the connection string (I usually copy it from the SQLDataSource Object), and execute your sql command.

Dim Conn as ADODB.Connection

Conn.ConnectionString = "Provider..."

Conn.Execute(InsertCommand)

Holler at me for any clarifications

|||I forgot, for 2 after Dim Conn as ADODB.Connection you have to put Conn = new ADODB.Connection|||You can try this one at your button submit click event using text1 as your control.

Dim datasourceAsNew SqlDataSource()

datasource.ConnectionString = ConfigurationManager.ConnectionStrings("YourConnectionString").ToString()

datasource.InsertCommandType = SqlDataSourceCommandType.Text

datasource.InsertCommand ="INSERT INTO YourTable (YourTableField) VALUES (@.YourTableField)"

datasource.InsertParameters.Add(

"YourTableField", Text1.Text)

|||You can try this one at your button submit click event using text1 as your control.

Dim datasourceAsNew SqlDataSource()

datasource.ConnectionString = ConfigurationManager.ConnectionStrings("YourConnectionString").ToString()

datasource.InsertCommandType = SqlDataSourceCommandType.Text

datasource.InsertCommand ="INSERT INTO YourTable (YourTableField) VALUES (@.YourTableField)"

datasource.InsertParameters.Add(

"YourTableField", Text1.Text)

|||

this last example was awesome. It was implistic and really helped. I understand much more now. I new that I was going to have to use the parameters.add functionality. I think I am messing up on my connection string though and it is probably just not set correctly. I get an unhandled exception here is the error message:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_1cnoj4u7"
StackTrace:
at _Default.SendForm_Click(Object sender, EventArgs e) in D:\Documents and Settings\ronin\My Documents\Visual Studio 2005\WebSites\ADRequest\Default.aspx.vb:line 20
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Here is line 20 - the connection string:

datasource.ConnectionString = ConfigurationManager.ConnectionStrings("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\adrequest.mdf;Integrated Security=True;User Instance=True").ToString()

I am using a built in SQLDB file that comes with VWD2005E, and the file is called adrequest.mdf, what am I missing here.

TIA,

Chris

|||

You are wrong with declaring with your connection string. Your connection string name must be like in my part:

phiwugdatasource.ConnectionString = ConfigurationManager.ConnectionStrings("phiwugConnectionString1").ToString()


To find the name of your connection string, try to do this, add a blank web form on your project, go to database explorer and go to the table of your database, click the table and drag and drop this to the blank web form. You will see that it will create a table on your blank web form and a control name SqlDataSource - SqlDataSource1. Click it then click the arrow next to it and you will see Configure Data Source and click it. Next a wizard will appear. The connection string name that will appear on the drop down list box is the connection string name you will write on it.

Be sure to mark as answer on the post you think that answers your question so that the poster will have credit for it. Don't hesitate to inquire.

Best regards,

|||

This may be a silly question but given this code:

Dim datasource As New SqlDataSource()
datasource.ConnectionString = ConfigurationManager.ConnectionStrings("connection2").ToString()
datasource.InsertCommandType = SqlDataSourceCommandType.Text
datasource.InsertCommand = "INSERT INTO ticket (sr) VALUES (@.srnum)"
datasource.InsertParameters.Add("srnum", TextBoxSRNum.Text)

is the data actually being posted to the DB or is the insert statement just being setup? Do I need to actually execute the statement through another line?

TIA - Chris

|||

Nevermind

I just added datasurce.Insert() to the end of the event - that fixed it - thanks everyone for helping out!

- Chris

|||

You can even add this one and put your datasource.insert() on a structured error handling procedure:

Dim

rowsaffectedAsIntegerTry

rowsaffected = datasource.Insert()

Catch exAs Exception'TODO: Probably write a windows error log

Server.Transfer(

"error.aspx") <--create a web form for error messages/siteFinally

datasource =

Nothing

EndTry

If rowsaffected <> 1Then

Server.Transfer(

"error.aspx") <--create a web form for error messages/siteElse

Server.Transfer(

"success.aspx") <--create a web form for success messages/site

EndIf

Monday, March 12, 2012

Non Windows App connecting to SQL Server using Windows Auth

How can a non Windows App , say an app that runs on Linux connect to SQL
Server using Windows Auth ?
Has anyone done that ? How does Linux integrate with Windows ? Are there 3rd
party tools ?
We know SQL Auth would work but we want to use Windows Auth only.
Please let me know
ThanksTypically a Linux box uses something like FreeTDS to connect to a SQL
Server machine. FreeTDS supports both forms of authentication:
http://www.freetds.org/faq.html

Non Windows App connecting to SQL Server using Windows Auth

How can a non Windows App , say an app that runs on Linux connect to SQL
Server using Windows Auth ?
Has anyone done that ? How does Linux integrate with Windows ? Are there 3rd
party tools ?
We know SQL Auth would work but we want to use Windows Auth only.
Please let me know
ThanksTypically a Linux box uses something like FreeTDS to connect to a SQL
Server machine. FreeTDS supports both forms of authentication:
http://www.freetds.org/faq.html

Saturday, February 25, 2012

No XML export

...Newbie alert...
I am picking up a project that makes significant use of SQL2005 reporting
services. The app, as it is currently, triggers the report by launching a new
window with a URL pointing at the report server and including the parameters
rs:Command=Render&rs:clearsession=true&rs:format=HTML4.0
The new window shows the "Report is being generated" message and eventually
it is displayed. I want to get the XML version of the report, but the EXPORT
drop down only offers Excel and PDF.
This seems to be consistent with a .net report viewer control in "local
mode" (whatever that is), but I don't think that this is what's going on.
If I go to the reportserver virtual directory, there is a
ReportServer.config file. It contains, in part the following:
<ExcludedRenderFormats>
<RenderingExtension>HTMLOWC</RenderingExtension>
<RenderingExtension>NULL</RenderingExtension>
<RenderingExtension>RGDI</RenderingExtension>
</ExcludedRenderFormats>
under <Delivery> for various <Extension Name="..."> tags
It also shows
<Render>
<Extension Name="XML"
Type="Microsoft.ReportingServices.Rendering.XmlDataRenderer.XmlDataReport,Microsoft.ReportingServices.XmlRendering"/>
...
So it doesn't seem to actively exclude xml rendering and it does seem to
provide a renderer for the file type.
I've done this using the client's service provider and also on my own
out-of-the-box SQL2005 installation and have the same result on each.
I'm obviously missing something silly, but I can't figure out what it is.
Thx
MarcOn Sep 17, 3:08 pm, MarcG <JoePt...@.newsgroup.nospam> wrote:
> ...Newbie alert...
> I am picking up a project that makes significant use of SQL2005 reporting
> services. The app, as it is currently, triggers the report by launching a new
> window with a URL pointing at the report server and including the parameters
> rs:Command=Render&rs:clearsession=true&rs:format=HTML4.0
> The new window shows the "Report is being generated" message and eventually
> it is displayed. I want to get the XML version of the report, but the EXPORT
> drop down only offers Excel and PDF.
> This seems to be consistent with a .net report viewer control in "local
> mode" (whatever that is), but I don't think that this is what's going on.
> If I go to the reportserver virtual directory, there is a
> ReportServer.config file. It contains, in part the following:
> <ExcludedRenderFormats>
> <RenderingExtension>HTMLOWC</RenderingExtension>
> <RenderingExtension>NULL</RenderingExtension>
> <RenderingExtension>RGDI</RenderingExtension>
> </ExcludedRenderFormats>
> under <Delivery> for various <Extension Name="..."> tags
> It also shows
> <Render>
> <Extension Name="XML"
> Type="Microsoft.ReportingServices.Rendering.XmlDataRenderer.XmlDataReport,Microsoft.ReportingServices.XmlRendering"/>
> ...
> So it doesn't seem to actively exclude xml rendering and it does seem to
> provide a renderer for the file type.
> I've done this using the client's service provider and also on my own
> out-of-the-box SQL2005 installation and have the same result on each.
> I'm obviously missing something silly, but I can't figure out what it is.
> Thx
> Marc
If you are using SQL Server 2005 Express Edition w/Advanced Services,
according to MS's documentation, you will not be able to export to XML
(refer to: http://technet.microsoft.com/en-us/library/ms157153.aspx );
however, I'm using that version w/SP2 and can export to Tiff and XML.
If you don't have SP2 installed, you may want to do that. Hope this
helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||Enrique,
I'm not sure how to find the equivalent of "Help|About" to get the version
info, but the SQL Server Configuration Manager at the hosted site shows
Version-9.2.3042.00 and File Version 2005.090.3054.00. I can't find the
equivalent information for the Report Server.
Marc|||Actually, I didn't report this properly...
Both the hosting service and my test machine have near identical
reReportServer.config files.
They differ only in <dsn>, IInstallationID>,<UrlRoot>, and
WebServiceAccount> tags.
On the hosting service, Export offers only Excel and PDF. On my test host, I
get Excel, PDF, XML, csv, TIFF, and Web Archive, as expected.
So it appears that the answer is not in the config file. Is there a way that
I can confirm that the required renderers are installed on the hosting
service?
Thx|||Hello Joe,
I would like to know this issue more clearly.
Do you mean that you want to develop a windows form application to access
the Report via web access and you want to Export it via XML?
If so, please let me know whether you could Export the report to XML
directly in Report Server.
The Render Extension for the Reporting Services is specified in the
ReportServer.config file
Also, you could try to use the command parameter like this to export the
report to XML directly.
rs:Command=Render&rs:clearsession=true&rs:format=XML
Hope this helps.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Wei,
I want to have the report viewer that is used by default in IE. I DO NOT
want to use the .NET report viewer control. I want to leave the initial
display in HTML for viewing but allow for exporting and saving in XML. As I
said in the previous post, the rsreportserver.config files are effectively
identical on the two machines and I get the XML export optioin on my local XP
system but not on the hosted one.
I am a little confused about the installation that I am seeing on the
hosting service. Using the IIS Manager, I see the following...
Local Computer
Application Pools
AppPoolforRS
RManager (a "gear" icon, path is <ICCS>/RManager)
RServer (a "gear" icon, path is <ICCS>/RServer)
DefaultAppPool
Default Application (empty)
Default Application (empty)
Reports (empty)
ReportServer (empty)
MSSharePointAppPool
Root (empty)
Default Application (empty)
Web Sites
Default Web Site (stopped)
Microsoft SHarePoint Administration
ICCS
Reports ("gear" icon, path is C:\Program Files\Microsoft SQL
Server\MSSQL.2\Reporting Services\ReportManager)
ReportServer ("gear" icon, path is C:\Program Files\Microsoft SQL
Server\MSSQL.2\Reporting Services\ReportServer)
RManager ("gear" icon, path is C:\Program Files\Microsoft SQL
Server\MSSQL.2\Reporting Services\ReportManager)
RServer ("gear" icon, path is C:\Program Files\Microsoft SQL
Server\MSSQL.2\Reporting Services\ReportServer)
In the ReportServer directory, I have (with other files),
rsreportserver.config
rsreportserversp2update.config
rssrvrpolicy.config
web.config
These files match (by name) the files I have in the same directory on my
local WinXP test machine. There is no file named "reportserver.config" on
either machine.
By way of an experiment, on the hosted system I made copies of
rsreportserver.config and rsreportserversp2update.config and renamed them
reportserver.config and reportserversp2update.config. I then stopped and
restarted the ICCS web site and stopped and restarted the AppPoolforRS. This
made no difference.|||Hell Joe,
Sorry for mistyping. It should be rsreportserver.config.
The <Render> part in my side is like this:
<Render>
<Extension Name="XML"
Type="Microsoft.ReportingServices.Rendering.XmlDataRenderer.XmlDataReport,Mi
crosoft.ReportingServices.XmlRendering"/>
<Extension Name="NULL"
Type="Microsoft.ReportingServices.Rendering.NullRenderer.NullReport,Microsof
t.ReportingServices.NullRendering" Visible="false"/>
<Extension Name="CSV"
Type="Microsoft.ReportingServices.Rendering.CsvRenderer.CsvReport,Microsoft.
ReportingServices.CsvRendering"/>
<Extension Name="IMAGE"
Type="Microsoft.ReportingServices.Rendering.ImageRenderer.ImageReport,Micros
oft.ReportingServices.ImageRendering"/>
<Extension Name="PDF"
Type="Microsoft.ReportingServices.Rendering.ImageRenderer.PdfReport,Microsof
t.ReportingServices.ImageRendering"/>
<Extension Name="RGDI"
Type="Microsoft.ReportingServices.Rendering.ImageRenderer.RemoteGdiReport,Mi
crosoft.ReportingServices.ImageRendering" Visible="false"
LogAllExecutionRequests="false"/>
<Extension Name="HTML4.0"
Type="Microsoft.ReportingServices.Rendering.HtmlRenderer.Html40RenderingExte
nsion,Microsoft.ReportingServices.HtmlRendering" Visible="false"
LogAllExecutionRequests="false"/>
<Extension Name="HTML3.2"
Type="Microsoft.ReportingServices.Rendering.HtmlRenderer.Html32RenderingExte
nsion,Microsoft.ReportingServices.HtmlRendering" Visible="false"/>
<Extension Name="MHTML"
Type="Microsoft.ReportingServices.Rendering.HtmlRenderer.MHtmlRenderingExten
sion,Microsoft.ReportingServices.HtmlRendering"/>
<Extension Name="EXCEL"
Type="Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer,Micr
osoft.ReportingServices.ExcelRendering"/>
</Render>
You need to check whether you have this
Microsoft.ReportingServices.XmlRendering.dll under the folder:
C:\Program Files\Microsoft SQL Server\MSSQL.2\Reporting
Services\ReportServer\bin
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Wei Lu,
Unfortunately, my config matches what you sent me exactly, and
Microsoft.ReportingServices.XmlRendering.dll is in C:\Program Files\Microsoft
SQL Server\MSSQL.2\Reporting Services\ReportServer\bin
File version is 9.0.3042.0
'
Marc|||Hello Marc,
I would like to get the screenshot of your issue.
Also, have you applied the latest service pack of SQL 2005?
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Wei Lu,
I'm not sure what you want for a screen shot. I am looking at an IE5 browser
window with the HTML version of the report displayed. There is a drop down
box that says "Select a Format" and when you click it, it offers only
"Acrobat (PDF) File", and "Excel" If you send me an email address, I'll send
you the screen shot.
As noted earlier, I don't know how to ask SQL2005 what its SP level is. I
provided you with the file version numbers for the relevant DLL's
Marc|||Hello Marc,
You may send the email to me. Please remove the ONLINE in my display email
address. Thank you!
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.