Click here to Skip to main content
12,953,349 members (47,278 online)
Rate this:
 
Please Sign up or sign in to vote.
I have created database name Notes.Table name tbNotes. Column names are NotesID(int),
Notes(Varchar), Client(Varchar),Date(DateTime),Category(Varchar).

Here is my Code for webservices....

[WebMethod]
public int AddNotes(int NotesID, string Notes,string Client, string Date, string Category)
{
 
string strConn="Data Source=#####; Initial Catalog=Notes;uid=sa; pwd=####;";
SqlConnection cnn = new SqlConnection(strConn);
cnn.Open();
 
SqlCommand cmd = new SqlCommand();
cmd.Connection = cnn;
 
cmd.CommandText =
 
"insert into tbNotes(NotesID,Notes,Client,Data,Category)values (" + NotesID + ",'" + Notes + "','" + Client + "','" + Date + "', " + Category + ")";
int i = cmd.ExecuteNonQuery();
cnn.Close();
 
return i;
}

private void button1_Click(object sender, EventArgs e)
{
 
if (txtnotesid.Text == "" || txtnotes.Text == "" || txtclient.Text == "" || category.Text == "")
{
MessageBox.Show("Please Enter The Details");
}
 
else
{
notesapp.WebService1 obj = new notesapp.WebService1();
}
Posted 7-Dec-12 21:39pm
Updated 7-Dec-12 22:12pm
v3
Comments
Krunal Rohit 8-Dec-12 3:44am
   
and your problem is........?????????
Ritesh Zaveri 8-Dec-12 3:53am
   
after adding details in form and then click on save button, my details should be stored in database using web services method
Krunal Rohit 8-Dec-12 4:02am
   
Okay, so where's your Save Button code ???
Ritesh Zaveri 8-Dec-12 4:11am
   
Save Button Code is in window form file...

private void button1_Click(object sender, EventArgs e)
{

if (txtnotesid.Text == "" || txtnotes.Text == "" || txtclient.Text == "" || category.Text == "")
{
MessageBox.Show("Please Enter The Details");
}

else
{
notesapp.WebService1 obj = new notesapp.WebService1();
}
Ritesh Zaveri 8-Dec-12 4:30am
   
Thanks...:)
Krunal Rohit 8-Dec-12 4:32am
   
Cheers mate. :) All the best :) :)
Ritesh Zaveri 8-Dec-12 4:35am
   
Whats is StatuLabel.Text??
Krunal Rohit 8-Dec-12 4:38am
   
that's optional... ExecuteNonQuery returns no of rows affected, so I've displayed over there..
Ritesh Zaveri 8-Dec-12 5:03am
   
I have written parameters like this in Window form :: objService.AddNotes(txtnotesid.Text,txtnotes.Text,txtclient.Text,datetime.Text,category.Text);
and in webservice method my parameteres are like this :: public int AddNotes(string NotesID, string Notes, string Client, string Date, string Category)....
Ritesh Zaveri 8-Dec-12 5:04am
   
But Getting Error like
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Data.SqlClient.SqlException: The name "Marketing" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
Ritesh Zaveri 8-Dec-12 5:05am
   
Marketing is a item in Category... Category contains combobox having items like Marketing,Sales,General,Operational,Payment.
Krunal Rohit 8-Dec-12 5:09am
   
ComboBox.SelectedItem.ToString();
Ritesh Zaveri 8-Dec-12 5:14am
   
Still getting same error as above Soap Handled Exception::
The name "Marketing" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
Krunal Rohit 8-Dec-12 5:17am
   
Category is your table column name... Make changes as per this
Ritesh Zaveri 8-Dec-12 5:19am
   
What changes??
Krunal Rohit 8-Dec-12 5:45am
   
Column name is not permitted and its seems like you're passing Column name.. So accordingly make changes.. ;)
Ritesh Zaveri 8-Dec-12 6:04am
   
Thanks...:) Now it works..:)
Krunal Rohit 8-Dec-12 6:08am
   
Good Day :)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

private void button1_Click(object sender, EventArgs e)
{
 
if (txtnotesid.Text == "" || txtnotes.Text == "" || txtclient.Text == "" || category.Text == "")
{
MessageBox.Show("Please Enter The Details");
}
 
else
{
notesapp.WebService1 obj = new notesapp.WebService1();
int n = obj.AddNotes(txtnotesid.Text,txtnotes.Text,txtclient.Text,category.Text);
StatuLabel.Text = n.ToString();
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,920


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 8 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100