Problem with insert statement

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Feb 2009
Posts: 29
Reputation: mem81 is an unknown quantity at this point 
Solved Threads: 0
mem81 mem81 is offline Offline
Light Poster

Problem with insert statement

 
0
  #1
Feb 24th, 2009
Hello,

I am trying to get the currently selected values from dropdown lists and textboxes from a web page and write them to an access database.
I am using MS Web Developer 2005 Express.
To do that I have created data Source , for the InsertQuery Property of the DataSource I have the following:

  1. INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName,Reportingperiod) VALUES ('@CedantID', '@CompanyType', '@CompanyName', '@TypeOfFile', '@FullFileName','@ReportingPeriod')

Then I have Created button and on it`s onclick event I have

nameOfDataSet(qryaddRecods).Insert()
When I click on the button , it does write a row in the table .
The problem is instead of getting the selected values , it returns parameters as described in the insert query.
Instead of selected reporting period (2009-02-28) I get @ReportingPeriod, instead of CedantID (1111) I get @ CedantID in the table.

Could you please tell me if you have an idea where my problem is .

Thanks in advance
Last edited by peter_budo; Feb 25th, 2009 at 8:38 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 18
Reputation: Bandar.M.A is an unknown quantity at this point 
Solved Threads: 1
Bandar.M.A Bandar.M.A is offline Offline
Newbie Poster

Re: Problem with insert statement

 
0
  #2
Feb 24th, 2009
Hi ;

please sent your code so i can know where is the error
'btw'
are you using sp?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 29
Reputation: mem81 is an unknown quantity at this point 
Solved Threads: 0
mem81 mem81 is offline Offline
Light Poster

Re: Problem with insert statement

 
0
  #3
Feb 24th, 2009
Originally Posted by mem81 View Post
Hello,

I am trying to get the currently selected values from dropdown lists and textboxes from a web page and write them to an access database.
I am using MS Web Developer 2005 Express.
To do that I have created data Source , for the InsertQuery Property of the DataSource I have the following:

INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName,Reportingperiod) VALUES ('@CedantID', '@CompanyType', '@CompanyName', '@TypeOfFile', '@FullFileName','@ReportingPeriod')

Then I have Created button and on it`s onclick event I have

nameOfDataSet(qryaddRecods).Insert()

When I click on the button , it does write a row in the table .
The problem is instead of getting the selected values , it returns parameters as described in the insert query.
Instead of selected reporting period (2009-02-28) I get @ReportingPeriod, instead of CedantID (1111) I get @ CedantID in the table.

Could you please tell me if you have an idea where my problem is .

Thanks in advance
Hi thanks for reply,

Here is the code behind the page:
  1. <System.Serializable()> Partial Class _Default
  2.  
  3.  
  4. Inherits System.Web.UI.Page
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  13.  
  14. End Sub
  15. Public Property SelectedDate() As Date
  16. Get
  17. Return Date.Parse(Me.TextBox1.Text)
  18.  
  19. End Get
  20.  
  21. Set(ByVal value As Date)
  22. Me.TextBox1.Text = value.ToShortDateString()
  23. End Set
  24.  
  25.  
  26. End Property
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
  39.  
  40.  
  41.  
  42.  
  43.  
  44. End Sub
  45.  
  46. Protected Sub Calendar1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.Disposed
  47.  
  48. End Sub
  49.  
  50. Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
  51. TextBox1.Text = Calendar1.SelectedDate.ToShortDateString
  52. Me.Calendar1.Visible = False
  53.  
  54.  
  55. End Sub
  56.  
  57. Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  58. If Me.Calendar1.Visible = False Then
  59.  
  60.  
  61. Me.Calendar1.Visible = False
  62. Else
  63. Me.Calendar1.Visible = True
  64. End If
  65. End Sub
  66.  
  67. Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  68. If Calendar1.Visible = False Then
  69. Calendar1.Visible = True
  70.  
  71. End If
  72. End Sub
  73.  
  74. Protected Sub DDTypeOfFile_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDTypeOfFile.SelectedIndexChanged
  75.  
  76. End Sub
  77.  
  78. Protected Sub ReciptDate_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles ReciptDate.Load
  79.  
  80. ReciptDate.Text = Date.Now.ToString("d")
  81.  
  82.  
  83. End Sub
  84.  
  85. Protected Sub ReciptDate_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles ReciptDate.PreRender
  86.  
  87. End Sub
  88.  
  89.  
  90. Protected Sub DDCompanyType_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDCompanyType.DataBound
  91.  
  92.  
  93. End Sub
  94.  
  95. Protected Sub DDCompanyType_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDCompanyType.Load
  96.  
  97. End Sub
  98.  
  99. Protected Sub DDCompanyType_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDCompanyType.SelectedIndexChanged
  100.  
  101.  
  102.  
  103. End Sub
  104.  
  105. Protected Sub DDCedantID_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDCedantID.Load
  106. If Not Page.IsPostBack Then
  107.  
  108. Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\DataStatusRecord1.mdb")
  109. Dim strSQL As String = "SELECT distinct CedantID FROM Recording"
  110. Dim da As New System.Data.OleDb.OleDbDataAdapter(strSQL, conn)
  111. Dim ds As New Data.DataSet
  112. da.Fill(ds, "Recording")
  113. With Me.DDCedantID
  114. .DataSource = ds.Tables("Recording")
  115. .DataTextField = "CedantID"
  116. .DataValueField = "CedantID"
  117. .DataBind()
  118.  
  119.  
  120. End With
  121. End If
  122.  
  123.  
  124. End Sub
  125.  
  126. Protected Sub DDCedantID_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDCedantID.SelectedIndexChanged
  127.  
  128.  
  129. End Sub
  130.  
  131. Protected Sub btnAddRecords_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddRecords.Click
  132. 'Add the new product!
  133. qryAddRecords.Insert()
  134.  
  135.  
  136.  
  137.  
  138. End Sub
  139.  
  140. Protected Sub DDTest_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDTest.SelectedIndexChanged
  141.  
  142. End Sub
  143.  
  144. Protected Sub FileName_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileName.Init
  145.  
  146. End Sub
  147.  
  148. Protected Sub FileName_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileName.PreRender
  149. FileName.Text = String.Format("{0:d}-{1}-{2}", Me.Calendar1.SelectedDate, Me.CompShortName.SelectedValue, Me.DDTypeOfFile.SelectedValue)
  150.  
  151. End Sub
  152.  
  153. Protected Sub FileName_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileName.TextChanged
  154.  
  155. End Sub
  156.  
  157. Protected Sub CompShortName_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CompShortName.SelectedIndexChanged
  158.  
  159. End Sub
  160. End Class
  161.  
  162.  
  163. and I am using query where I use parameters , that I have put in the insert property of the datasource called qryAddRecords.
  164.  
  165. Here is the source code as well:
  166.  
  167. <%@ Page Language="VB" CodeFile="Default.aspx.vb" AutoEventWireup="true" Inherits="_Default" %>
  168. <html>
  169.  
  170. <head runat="server">
  171.  
  172. <title>CompanySelection</title>
  173.  
  174.  
  175. </head>
  176. <body>
  177. <form id="form1" runat="server">
  178. <asp:panel ID=Controls1 style="Z-INDEX: 181; LEFT: 0px; VISIBILITY:visible; POSITION: absolute; TOP: 0px"
  179. runat="server" BackColor="Transparent" Height="500px" Width="1000px" Design_Time_Lock="True" CssClass="textcenter" HorizontalAlign="Center">
  180.  
  181. <div style="left:0px;Width:988px;BORDER-RIGHT-STYLE: outset; BORDER-LEFT-STYLE: outset;
  182. POSITION: absolute; TOP: 0px; HEIGHT: 498px; BACKGROUND-COLOR:Ivory; TEXT-ALIGN: center; BORDER-BOTTOM-STYLE: outset" >
  183.  
  184. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
  185. <asp:Label ID="Label1" runat="server" Text="Select Cedant ID:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:20px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent"></asp:Label>
  186.  
  187. &nbsp; &nbsp; &nbsp;&nbsp;<asp:DropDownList ID="DDCedantID" runat="server" Style="Z-INDEX:100; LEFT:250px;Position:absolute;TOP:20px" Height="20px" Width="125px">
  188. </asp:DropDownList>
  189. &nbsp;&nbsp;&nbsp;&nbsp;<br />
  190. <br />
  191. &nbsp;&nbsp;
  192. <asp:DropDownList ID="DDCompanyType" runat="server" DataSourceID="dsCompanyType"
  193. DataTextField="CompanyType" DataValueField="CompanyType" Style="Z-INDEX:100; LEFT:250px;Position:absolute;TOP:50px" Height="20px" Width="125px" AppendDataBoundItems="True">
  194. <asp:ListItem Selected="True"></asp:ListItem>
  195. </asp:DropDownList>
  196. <asp:AccessDataSource ID="dsCompanyType" runat="server" DataFile="C:\DB\DataStatusRecord1.mdb"
  197. SelectCommand="SELECT DISTINCT [CompanyType] FROM [Recording]
  198. where CedantID= @CedantID
  199. ">
  200. <SelectParameters>
  201. <asp:ControlParameter ControlID="DDCedantID" Name="CedantID" PropertyName="SelectedValue" />
  202. </SelectParameters>
  203. </asp:AccessDataSource>
  204. &nbsp;
  205.  
  206. <br />
  207. <asp:Label ID="Label2" runat="server" Text="Pick Company Type:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:50px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent"></asp:Label>
  208. <asp:DropDownList ID="DDCompName" runat="server" DataSourceID="dsCompName" DataTextField="CompanyName"
  209. DataValueField="CompanyName" Style="Z-INDEX:100; LEFT:250px;Position:absolute;TOP:110px" Height="20px" Width="125px">
  210. </asp:DropDownList >
  211.  
  212.  
  213. <asp:AccessDataSource ID="dsCompName" runat="server" DataFile="C:\DB\DataStatusRecord1.mdb"
  214. SelectCommand="SELECT DISTINCT [CompanyName] FROM [Recording]">
  215. </asp:AccessDataSource>
  216.  
  217.  
  218. <br />
  219.  
  220. <asp:Label ID="Label3" runat="server" Text="Select Reporting Period:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:140px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent"></asp:Label>
  221. <asp:TextBox ID="TextBox1" runat="server" Style="Z-INDEX:100; LEFT:250px; POSITION: absolute; TOP:140px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="124px" Height="20px" BackColor=Info BorderStyle="Solid" BorderWidth="1px" BorderColor="Black"></asp:TextBox>
  222. &nbsp;<br />
  223. <asp:Button ID="Button1" runat="server" Text="..." Style="Z-INDEX:100; LEFT:390px; POSITION: absolute; TOP:140px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="24px" Height="20px" BackColor=ButtonShadow BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent" ForeColor="#C0C0FF">
  224. </asp:Button>
  225. <asp:Label ID="Label4" runat="server" Text="Select Type Of File:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:80px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent">
  226. </asp:Label>
  227. <asp:DropDownList ID="DDTypeOfFile" runat="server" DataSourceID="dsFileType" DataTextField="TypeOfFile"
  228. DataValueField="TypeOfFile" Style="Z-INDEX:100; LEFT:250px;Position:absolute;TOP:80px" Height="20px" Width="125px">
  229.  
  230. </asp:DropDownList >
  231. <asp:AccessDataSource ID="dsFileType" runat="server" DataFile="C:\DB\DataStatusRecord1.mdb"
  232. SelectCommand="SELECT DISTINCT [TypeOfFile] FROM [Recording]">
  233. </asp:AccessDataSource>
  234. <asp:Calendar ID="Calendar1" runat="server" Visible="False" Style="Z-INDEX:100; LEFT:415px;Position:absolute;TOP:140px" Height="50px" Width="195px">
  235.  
  236. </asp:Calendar>
  237. <asp:Label ID="Label5" runat="server" Text="Select Company Name:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:110px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent">
  238. </asp:Label>
  239. <asp:Label ID="Label6" runat="server" Text="Receipt Date:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:170px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent">
  240.  
  241. </asp:Label>
  242. <asp:TextBox ID="ReciptDate" runat="server" Style="Z-INDEX:100; LEFT:250px; POSITION: absolute; TOP:170px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="124px" Height="20px" BackColor=Info BorderStyle="Solid" BorderWidth="1px" BorderColor="Black">
  243. </asp:TextBox>
  244. <asp:Label ID="RowFileName" runat="server" Text="Row File Name:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:200px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent"></asp:Label>
  245. <asp:DropDownList ID="DDRawFileName" runat="server"
  246. Style="Z-INDEX:100; LEFT:250px;Position:absolute;TOP:200px" Height="20px" Width="125px" DataSourceID="dsRawFileName" DataTextField="BasicFileName" DataValueField="BasicFileName">
  247.  
  248. </asp:DropDownList >
  249. <asp:AccessDataSource ID="dsRawFileName" runat="server" DataFile="C:\DB\DataStatusRecord1.mdb"
  250. SelectCommand="SELECT DISTINCT [BasicFileName] FROM [Recording]">
  251. </asp:AccessDataSource>
  252. &nbsp; &nbsp;
  253. <asp:Label ID="Label7" runat="server" Text="CompanyShortName:" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:230px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent">
  254. </asp:Label>
  255. <asp:DropDownList ID="CompShortName" runat="server"
  256. Style="Z-INDEX:100; LEFT:250px;Position:absolute;TOP:230px" Height="20px" Width="125px" DataSourceID="dsCompShortName" DataTextField="BasicCompanyName" DataValueField="BasicCompanyName">
  257.  
  258. </asp:DropDownList >
  259. <asp:AccessDataSource ID="dsCompShortName" runat="server" DataFile="C:\DB\DataStatusRecord1.mdb"
  260. SelectCommand="SELECT DISTINCT [BasicCompanyName] FROM [Recording]">
  261. </asp:AccessDataSource>
  262. <asp:Label ID="Label8" runat="server" Text="File Name is :" Style="Z-INDEX:100; LEFT:5px; POSITION: absolute; TOP:260px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="162px" Height="18px" BackColor=Control BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent">
  263. </asp:Label>
  264. <asp:TextBox ID="FileName" runat="server" Style="Z-INDEX:100; LEFT:250px; POSITION: absolute; TOP:260px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="412px" Height="20px" BackColor=Info BorderStyle="Solid" BorderWidth="1px" BorderColor="Black"></asp:TextBox>
  265. &nbsp; &nbsp;
  266. <asp:Button ID="btnAddRecords" runat="server" Text= "Submit" Style="Z-INDEX:100; LEFT:420px; POSITION: absolute; TOP:290px" CssClass="textFont14WhiteBold + padding5Top" Design_Time_Lock="True" Width="72px" Height="20px" BackColor=ButtonShadow BorderStyle="Solid" BorderWidth="1px" BorderColor="Transparent" ForeColor="#C0C0FF">
  267. </asp:Button>
  268.  
  269.  
  270. <asp:AccessDataSource ID="qryAddRecords" runat="server" DataFile="C:\DB\DataStatusRecord1.mdb" InsertCommand="INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName, ReportingPeriod, DateReceived) VALUES ('@CedantID', '@CompanyType', '@CompanyName', '@TypeOfFile', '@FullFileName', '@ReportingPeriod', '@ReciptDate')">
  271. <InsertParameters>
  272. <asp:ControlParameter ControlID="DDCedantID" Name="@CedantID" PropertyName="SelectedValue" />
  273. <asp:ControlParameter ControlID="DDCompanyType" Name="@CompanyType" PropertyName="SelectedValue" />
  274. <asp:ControlParameter ControlID="DDCompName" Name="@CompanyName" PropertyName="SelectedValue" />
  275. <asp:ControlParameter ControlID="DDTypeOfFile" Name="@TypeOfFile" PropertyName="SelectedValue" />
  276. <asp:ControlParameter ControlID="FileName" Name="@FullFileName" PropertyName="Text" />
  277. <asp:ControlParameter ControlID="TextBox1" Name="@ReportingPeriod" PropertyName="Text" />
  278. <asp:ControlParameter ControlID="ReciptDate" Name="@ReciptDate" PropertyName="Text" />
  279. </InsertParameters>
  280. </asp:AccessDataSource>
  281.  


Thanks very much for looking
Regards
Mem81
Last edited by peter_budo; Feb 25th, 2009 at 8:38 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: bcasp is an unknown quantity at this point 
Solved Threads: 10
bcasp bcasp is offline Offline
Light Poster

Re: Problem with insert statement

 
0
  #4
Feb 24th, 2009
Get rid of the surrounding ' for the values in your insert statement.

  1. INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName,Reportingperiod) VALUES ('@CedantID', '@CompanyType', '@CompanyName', '@TypeOfFile', '@FullFileName','@ReportingPeriod')

should probably be

  1. INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName,Reportingperiod) VALUES (@CedantID, @CompanyType, @CompanyName, @TypeOfFile, @FullFileName,@ReportingPeriod)

With Access, I've also had to do something like

  1. INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName,Reportingperiod) VALUES ([@CedantID], [@CompanyType], [@CompanyName], [@TypeOfFile], [@FullFileName],[@ReportingPeriod])
Last edited by peter_budo; Feb 25th, 2009 at 8:39 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 18
Reputation: Bandar.M.A is an unknown quantity at this point 
Solved Threads: 1
Bandar.M.A Bandar.M.A is offline Offline
Newbie Poster

Re: Problem with insert statement

 
0
  #5
Feb 24th, 2009
whay you don't use the simple way?

define function to execute
sub execute(p,p,p,p,p,p,.....) ' as many as you want!
'then
  1. Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\DataStatusRecord1.mdb")
  2. Dim strSQL As String = "insert into (TABLENAME) (C,C,....) values (p,p,p......p) "
  3. dim cmd as Data.OleDb.OleDbCommand
  4. cmd = new Data.OleDb.OleDbCommand(strSQL, conn)
  5. Dim da As New System.Data.OleDb.OleDbDataAdapter(cmd)
  6. Dim ds As New Data.DataSet
  7.  
  8. cmd.ExecuteNonQuery()
  9. 'da.fill(ds)
  10.  


something like this and don't forget to open and close connection

i hope this well help you

good luck!!!
Last edited by peter_budo; Feb 25th, 2009 at 8:40 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 29
Reputation: mem81 is an unknown quantity at this point 
Solved Threads: 0
mem81 mem81 is offline Offline
Light Poster

Re: Problem with insert statement

 
0
  #6
Feb 24th, 2009
Great thank you both,

bcasp I had to remove the single quotations around the parameters values and add square brackets as you suggested.
so [@ParameterName] instead of '@ParameterName'

Bandar M.A thank you very much to you toofor your exact reply . It hitted the point . Thanks.
Here is the final code :

  1. Protected Sub btnAddRecords_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddRecords.Click
  2. 'on click of a button insert records
  3. qryAddRecords.Insert()
  4. End Sub
  5. Private Sub execute(ByVal CedantID, ByVal CompanyType, ByVal CompanyName, ByVal TypeOfFile, ByVal FullFileName, ByVal ReportingPeriod, ByVal ReciptDate)
  6. 'handles getting the currently selected data in controls
  7. Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DB\DataStatusRecord1.mdb")
  8. Dim strSQL As String = "insert into (DataStatus) (CedantID,CompanyType,CompanyName,TypeOfFile,FileName,ReportingPeriod,DateReceived) values (@CedantID,@CompanyType,@CompanyName,@TypeOfFile,@FullFileName,@ReportingPeriod,@ReciptDate) "
  9. Dim cmd As Data.OleDb.OleDbCommand
  10. conn.Open()
  11. cmd = New Data.OleDb.OleDbCommand(strSQL, conn)
  12. Dim da As New System.Data.OleDb.OleDbDataAdapter(cmd)
  13. Dim qryAddRecords As New Data.DataSet
  14. da.Fill(qryAddRecords)
  15. cmd.ExecuteNonQuery()
  16. conn.Close()
  17.  
  18. End Sub

and the query I have on the insertquery propery of the data source qryAddRecords is:

  1. INSERT INTO DataStatus(CedantID, CompanyType, CompanyName, TypeOfFile, FileName, ReportingPeriod, DateReceived) VALUES ([@CedantID], [@CompanyType], [ @CompanyName], [@TypeOfFile], [@FullFileName], [@ReportingPeriod], [@ReciptDate])

Although when I try to preview the query execution it throws an error it works perfectly.

Thanks again.

I will mark the thread as Solved
Last edited by peter_budo; Feb 25th, 2009 at 8:40 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC