how to insert data from a table into MS Accesshttp://forums.asp.net/t/1766224.aspx/1?how+to+insert+data+from+a+table+into+MS+AccessThu, 09 Feb 2012 11:35:31 -050017662244817578http://forums.asp.net/p/1766224/4817578.aspx/1?how+to+insert+data+from+a+table+into+MS+Accesshow to insert data from a table into MS Access <pre class="prettyprint">public class AgentClass { SqlConnection cn; SqlCommand cmd; SqlDataReader dr; public AgentClass() { String cs; cs = ConfigurationManager.ConnectionStrings[&quot;LandBankConnectionString2&quot;].ConnectionString; cn=new SqlConnection(cs); cmd = new SqlCommand(); cmd.Connection=cn; cmd.CommandType = CommandType.Text; } public bool InsertRecordForAgent(string AgentName,string fulladdress, string address, string suburb, int postcode, string state, int phone, int fax, string email, string isactive, string notes, string contactname) { try { cmd.CommandText = &quot;insert into tbl_LB_Agent values(@AgentName,@fulladdress, @address, @suburb, @postcode, @state, @phone, @fax, @email, @isactive, @notes,@contactname)&quot;; cmd.Parameters.AddWithValue(&quot;@AgentName&quot;, AgentName); cmd.Parameters.AddWithValue(&quot;@address&quot;, address); cmd.Parameters.AddWithValue(&quot;@suburb&quot;, suburb); cmd.Parameters.AddWithValue(&quot;@postcode&quot;, postcode); cmd.Parameters.AddWithValue(&quot;@state&quot;, state); cmd.Parameters.AddWithValue(&quot;@phone&quot;, phone); cmd.Parameters.AddWithValue(&quot;@Fax&quot;, fax); cmd.Parameters.AddWithValue(&quot;@email&quot;, email); cmd.Parameters.AddWithValue(&quot;@isactive&quot;, isactive); cmd.Parameters.AddWithValue(&quot;@notes&quot;, notes); cmd.Parameters.AddWithValue(&quot;@contactname&quot;, contactname); cmd.Parameters.AddWithValue(&quot;@fulladdress&quot;, fulladdress); cn.Open(); cmd.ExecuteNonQuery(); cn.Close(); return true; } catch (Exception ex) { return false; } } protected void btnOk_Click1(object sender, EventArgs e) { string AgentName, fulladdress, address, suburb, state, email, notes, isactive, contactname; int postcode; int phone, fax; AgentName = txtName.Text; address = txtAddress.Text; suburb = txtSuburb.Text; postcode = int.Parse(txtPostCode.Text); state = txtState.Text; phone = int.Parse(txtPhone.Text); fax = int.Parse(txtFax.Text); email = txtEmail.Text; isactive = (txtActive.Text); notes = txtNotes.Text; contactname = &quot;&quot;; fulladdress = txtAddress.Text &#43; &quot;, &quot; &#43; txtSuburb.Text &#43; &quot;, &quot; &#43; txtState.Text; AgentClass Acl = new AgentClass(); if (Acl.InsertRecordForAgent(AgentName, fulladdress, address, suburb, postcode, state, phone, fax, email, isactive, notes, contactname) == true) { Label4.Text = &quot;record updated&quot;; } else { Label4.Text = &quot;error&quot;; } }</pre> 2012-02-06T03:41:18-05:004817598http://forums.asp.net/p/1766224/4817598.aspx/1?Re+how+to+insert+data+from+a+table+into+MS+AccessRe: how to insert data from a table into MS Access <p>Hi krishnapodduturi,</p> <p>Do you mean? Data insertion IN MS access table? if so, your code seems to be correct at a glance. please let us know is it error you are troubled with. Also, did you debug and proceeded to know the loc of code where you need help.</p> <p>bottom line, please elaborate the problem.</p> 2012-02-06T04:05:50-05:004817837http://forums.asp.net/p/1766224/4817837.aspx/1?Re+how+to+insert+data+from+a+table+into+MS+AccessRe: how to insert data from a table into MS Access <p>To insert into Access, you need to use the OleDb namespace instead of the SqlClient Namespace.</p> <p><a href="http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access">http://www.mikesdotnetting.com/Article/26/Parameter-Queries-in-ASP.NET-with-MS-Access</a></p> <p>And you forgot to specify the fulladdress parameter</p> 2012-02-06T06:25:02-05:004821460http://forums.asp.net/p/1766224/4821460.aspx/1?Re+how+to+insert+data+from+a+table+into+MS+AccessRe: how to insert data from a table into MS Access <p>Hello krishnapoddutri</p> <p>Use Oledb classes firstAnd</p> <p>Is there anything wrong with your codesAre you sharing a nice idea or solution about that</p> <p>Welcoem your feedbackBut plz first remove trycatch so as to let the error exposed directly</p> <p>Reguards</p> 2012-02-08T01:09:58-05:004821466http://forums.asp.net/p/1766224/4821466.aspx/1?Re+how+to+insert+data+from+a+table+into+MS+AccessRe: how to insert data from a table into MS Access <p>hi,</p> <p></p> <p>declare this namespace</p> <p>using System.data.oledb;</p> <p></p> <p>public Class Insert</p> <p>{</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;sqlconnection cn;</p> <p>&nbsp;&nbsp; &nbsp; sqlcommand cmd;</p> <pre class="prettyprint">cs = ConfigurationManager.ConnectionStrings[&quot;LandBankConnectionString2&quot;].ConnectionString);</pre> <p>&nbsp;&nbsp; &nbsp; &nbsp;sqlconnection cn = new sqlconnection (cs);</p> <p>&nbsp;&nbsp; &nbsp; cn.open();</p> <p>&nbsp;&nbsp; &nbsp; cmd = new sqlcommand(YourQueryString",cn);</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;int i = cmd.ExecuteNonQuery();</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;if (i == 1) then</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \\insert successful</p> <p>&nbsp;&nbsp; &nbsp; &nbsp;else</p> <p>&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \\inserting failed</p> <p></p> <pre class="prettyprint"> </pre> <p></p> <p></p> <p>}</p> 2012-02-08T01:16:05-05:004823678http://forums.asp.net/p/1766224/4823678.aspx/1?Re+how+to+insert+data+from+a+table+into+MS+AccessRe: how to insert data from a table into MS Access <p>Thanks for the reply guys.&nbsp;I really appreciate it.</p> <p>I am sorry to waste your time.&nbsp;I am new to asp.net forums and just sharing the code for data insertion into sql server for another member.</p> <p>I will make sure to include the details next time.</p> 2012-02-09T05:52:35-05:004824376http://forums.asp.net/p/1766224/4824376.aspx/1?Re+how+to+insert+data+from+a+table+into+MS+AccessRe: how to insert data from a table into MS Access &lt;div&gt; <p>Read word document -&nbsp;<a href="http://www.csharpaspnetarticles.com/2009/06/read-write-word-filestream-streamwriter.html">http://www.csharpaspnetarticles.com/2009/06/read-write-word-filestream-streamwriter.html</a>&nbsp;</p> <p>write excel document -&nbsp;<a href="http://blogs.msdn.com/b/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx">http://blogs.msdn.com/b/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx</a>&nbsp;</p> <p>areyy see this...for copying word doc to excel..Im unable to open them</p> &lt;/div&gt; 2012-02-09T11:35:31-05:00